Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string line;
- std::ifstream infile("highscore.txt");
- if (infile.is_open())
- {
- for (int i = 0; i < 10; i++)
- {
- getline(infile, line);
- highscores[i] = line;
- }
- infile.close();
- }
- int k = 0;
- for (int i = 0; i < 5; i++)
- {
- names[i] = highscores[k];
- k++;
- scores[i] = std::stof(highscores[k]);
- k++;
- }
- if (distance > scores[4]){
- // prompt for name
- std::string name = "Mark";
- scores[4] = distance;
- names[4] = name;
- if (distance > scores[3]){
- scores[4] = scores[3];
- names[4] = names[3];
- scores[3] = distance;
- names[3] = name;
- if (distance > scores[2]){
- scores[3] = scores[2];
- names[3] = names[2];
- scores[2] = distance;
- names[2] = name;
- if (distance > scores[1]){
- scores[2] = scores[1];
- names[2] = names[1];
- scores[1] = distance;
- names[1] = name;
- if (distance > scores[0]){
- scores[1] = scores[0];
- names[1] = names[0];
- scores[0] = distance;
- names[0] = name;
- }
- }
- }
- }
- }
- k = 0;
- for (int i = 0; i < 5; i++)
- {
- highscores[k] = names[i];
- k++;
- highscores[k] = std::to_string(scores[i]);
- k++;
- };
- std::ofstream outfile("highscore.txt");
- if (outfile.is_open())
- {
- for (int i = 0; i < 10; i++){
- outfile << highscores[i] << "\n";
- }
- outfile.close();
- }
- score = std::to_string(distance);
- const char *s = score.c_str();
- const char *hsdisplay[10] = { highscores[0].c_str(), highscores[1].c_str(), highscores[2].c_str(), highscores[3].c_str(), highscores[4].c_str(), highscores[5].c_str(), highscores[6].c_str(), highscores[7].c_str(), highscores[8].c_str(), highscores[9].c_str() };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement