### Reset function

I need the High scores reset, can you guys let me know how I would do that, my instructions are:

1. Print the high scores list to the screen (it will need to get this from the
High_Scores.txt file, so you'll want tocopy and paste the file into the same folder as Reset.vcproj).

2. Ask the user if they want to reset the high scores list.

3. If the user enters y, reset
the high scores text file to the original scores.

4. If the user says n, the progr
am doesn't have to do anything.

And then the code is below, Im not sure what you needed to help, here is the whole thing. Thank you in advance! I will greatly appreciate your help!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234`` `````` /* The Great Quiz Show Game by Keegan Mathur */ // Include the libraries #include #include #include //Use the standard namespace using namespace std; // Declare global variables int Guess; int Winnings; //Define the Question class class Question { private: string Question_Text; string Answer_1; string Answer_2; string Answer_3; string Answer_4; int Correct_Answer; int Prize_Amount; // How much the question is worth public: void setValues (string, string, string, string, string, int, int); void askQuestion ( ); }; void main ( ) { //Declare local variables int High_Score[5]; string High_Score_Name[5]; int Rank; // Initialize a high score at 0 High_Score[4] = 0; // Input the high scores from a file ifstream Input_High_Scores; Input_High_Scores.open ("High_Scores.txt"); for (int i = 0; i < 5; i++) { Input_High_Scores >> High_Score[i]; Input_High_Scores >> High_Score_Name[i]; } Input_High_Scores.close ( ); if (High_Score[4] == 0) { //Initialize local variables High_Score[0] = 25000; High_Score[1] = 12000; High_Score[2] = 7500; High_Score[3] = 4000; High_Score[4] = 2000; High_Score_Name[0] = "Gwyneth"; High_Score_Name[1] = "Adam"; High_Score_Name[2] = "Nastasia"; High_Score_Name[3] = "Nicolas"; High_Score_Name[4] = "Dani"; } // Show the title screen cout << "****************************" << endl; cout << "* *" << endl; cout << "* The Great Quiz Show Game *" << endl; cout << "* *" << endl; cout << "* by *" << endl; cout << "* *" << endl; cout << "* Your Name *" << endl; cout << "* *" << endl; cout << "****************************" << endl; cout << endl; // Create instances of Question Question q1; Question q2; Question q3; Question q4; Question q5; Question q6; // Set the values of the Question instances q1.setValues ("What does cout do?", "Eject a CD", "Send text to the printer", "Print text on the screen", "Play a sound", 3, 2500); q2.setValues ("What are the two sections in a class?", "public and local", "global and local", "global and private", "public and private", 4, 5000); q3.setValues ("What does cin do?", "Gets input from a file", "Gets input from the user", "Gets input from the computer", "Gets the letter c", 2, 2500); q4.setValues ("Which library lets you use the cout command?", "string", "cmath", "fstream", "iostream", 4, 4000); q5.setValues ("Which namespace have you used in this course?", "std", "public", "private", "include", 1, 3000); q6.setValues ("Which value below could an int variable hold?", "Harry", "-3.42", "792", "October 26", 3, 3000); // Ask the questions q1.askQuestion ( ); q2.askQuestion ( ); q3.askQuestion ( ); q4.askQuestion ( ); q5.askQuestion ( ); q6.askQuestion ( ); if (Winnings >= High_Score[4]) { //Get user's rank for (int i = 4; Winnings >= High_Score[i] && i >= 0; i--) { Rank =i; } //Rearrange the high scores list for (int i = 4; i != Rank; i--) { High_Score[i] = High_Score[i-1]; High_Score_Name[i] = High_Score_Name[i-1]; } cout << "You got a high score!" << endl; cout << "Please enter your name." << endl; cin >> High_Score_Name[Rank]; High_Score[Rank] = Winnings; } // Print the high score list cout << "High Score List" << endl; cout << endl; for (int i = 0; i< 5; i++) { cout << High_Score[i] << " " << High_Score_Name[i] << endl; } // Output the high scores to a file ofstream Output_High_Scores; Output_High_Scores.open ("High_Scores.txt"); for (int i = 0; i< 5; i++) { Output_High_Scores << High_Score[i] << endl; Output_High_Scores << High_Score_Name[i] << endl; } Output_High_Scores.close ( ); } // Stores values for Question variables void Question::setValues (string q, string a1, string a2, string a3, string a4, int ca, int pa) { Question_Text = q; Answer_1 = a1; Answer_2 = a2; Answer_3 = a3; Answer_4 = a4; Correct_Answer = ca; Prize_Amount = pa; } void Question::askQuestion ( ) { // Ask the question cout << endl; cout << Question_Text << endl; cout << "1. " << Answer_1 << endl; cout << "2. " << Answer_2 << endl; cout << "3. " << Answer_3 << endl; cout << "4. " << Answer_4 << endl; cout << endl; // Ask for a guess cout << "What is your answer?" << endl; cin >> Guess; // If user guesses right, add Prize_Amount to Winnings if (Guess == Correct_Answer) { cout << endl; cout << "You are correct." << endl; Winnings = Winnings + Prize_Amount; cout << "You just won \$" << Prize_Amount << "!" << endl; cout << "Total winnings: \$" << Winnings << endl; cout << endl; } else { cout << endl; cout << "You are not correct." << endl; cout << "Total winnings: \$" << Winnings << endl; cout << endl; } }``````
Last edited on
you reset the high score already on line 46 to 73. Just put it in a function like so:
 ``1234567891011121314`` ``````void ResetHighScore(int High_Score[5], string High_Score_Name[5]) { // Initialize a high score at 0 High_Score[4] = 0; // Input the high scores from a file ifstream Input_High_Scores; ... High_Score_Name[0] = "Gwyneth"; High_Score_Name[1] = "Adam"; High_Score_Name[2] = "Nastasia"; High_Score_Name[3] = "Nicolas"; High_Score_Name[4] = "Dani"; } }``````
and call the function accordingly
Would I want to put the near the end?
Anyone?
Doesn't matter, but make sure you tell the compiler that this is a function called ResetHighScore in advance. (If you're adding it to the end)

 ``1234567891011121314151617181920`` ``````//Tells the compiler that you're going to declare this function later on, // this will keep it from whining about a linker error. void ResetHighScore(int High_Score[5], string High_Score_Name[5]); // Your current program goes here void ResetHighScore(int High_Score[5], string High_Score_Name[5]) { // Initialize a high score at 0 High_Score[4] = 0; // Input the high scores from a file ifstream Input_High_Scores; ... High_Score_Name[0] = "Gwyneth"; High_Score_Name[1] = "Adam"; High_Score_Name[2] = "Nastasia"; High_Score_Name[3] = "Nicolas"; High_Score_Name[4] = "Dani"; } }``````
Topic archived. No new replies allowed.