Quiz show reset

Hello! I need some help with reseting the highscore on the quizshow.
the reset program must have: If the user answers 'y', Reset.exe resets the high scores list by writing
the original high scores to the High_Scores.txt file. (If the answer is 'n',
Reset.exe doesn't have to do anything.)

this program has many problems and one of them is that it does not recognize rewrite as a variable and I am not sure if I am rewriting the original high score list correctly. Please help me! Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  /*
The Great Quiz Show Game

by

Sun A Cho


*/

//Include the libraries
#include <iostream>
#include <string>
#include <fstream>

// Use the standard namespace
using namespace std;

// Declare global variables
int Guess;
int Winnings;
int ask;

// Define the Question class
class reset
{
private:
	string rewrite;
};

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;

	// Initiallize 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_Score.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] = 15000;
		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 *" << endl;
	cout << "*                     *" << endl;
	cout << "*          by         *" << endl;
	cout << "*					   *" << endl;
	cout << "*       Sun A Cho     *" << endl;
	cout << "*					   *" << endl;
	cout << "***********************" << endl;
	cout << endl;

	// Creat instances of Questions
	Question q1;
	Question q2;
	Question q3;
	Question q4;
	Question q5;
	Question q6;

	// Set the values of the Questions instances
	q1.setValues("What does cout do?",
		"Eject a CD",
		"Send text to the printer",
		"Print text on the screen",
		"Play 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 company",
		"Get 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 be 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[1 - i];
			High_Score_Name[i] = High_Score_Name[1 - i];
		}
		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 score 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();

	system("PAUSE");
}

// 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;
	}


}

void reset()
{
	int High_Score[5];
	string High_Score_Name[5];
	int Rank;

	cout << "Do you want to rest the high scores?" << endl;
	cin >> rewrite;
	if (rewrite == "y")
	{
		std::ofstream ofs;
		ofs.open("High_Scores.txt", std::ofstream::out | std::ofstream::trunc);
		ofs.close();

		int High_Score[5];
		string High_Score_Name[5];
		int Rank;

		// Initiallize 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_Score.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] = 15000;
			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";
		}

	
	}
	else if (rewrite == "n")
	{
		system("PAUSE");
	}
}



Last edited on
Create a class for the high scores. It should contain
- the 5 high scores and corresponding names
- read() and write() methods to read/write the scores to a stream.
- an int lowest() method to return the lowest high score.
- an add(int score, string &name) method to add a new score to the table.

You already have the code to do all of these things, but putting them in a class will keep the code organized better. Finally, you need to add:
- a void reset() method that resets the high scores to their initial values.

Once you have these methods, you can use them in your program to get the job done.
Here is your program re-implemented to use the HighScore class I mentioned. Search for "dmh" to see my changes. All you have to do is write the code for the HighScore methods.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
The Great Quiz Show Game

by

Sun A Cho


*/

//Include the libraries
#include <iostream>
#include <string>
#include <fstream>

// Use the standard namespace
using namespace std;

// Declare global variables
int Guess;
int Winnings;
int ask;

// dmh
class HighScore {
public:
    HighScore() {
	reset();
    }
    bool read(istream &is);
    bool write(ostream &os);
    unsigned lowest() {
	return scores[numScores-1];
    }
    void add(unsigned score, string &name);
    void reset();

    static constexpr size_t numScores=5;

    //scores sorted from highest to lowest
    unsigned scores[numScores];
    // corresponding names
    string names[numScores];
};

///////// DMH - put the code for the HighScores methods here.   //////


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();
};

int
main()
{

    // Declare local variables
    HighScore highScores;	// dmh

    // Input the high scores from a file
    ifstream Input_High_Scores;
    Input_High_Scores.open("High_Scores.txt"); // dmh careful with the name
    highScores.read(Input_High_Scores); // dmh
    Input_High_Scores.close();		// dmh
		    

    // Show the title screen
    cout << "***********************" << endl;
    cout << "*                     *" << endl;
    cout << "* The Great Quiz Show *" << endl;
    cout << "*                     *" << endl;
    cout << "*          by         *" << endl;
    cout << "*					   *" << endl;
    cout << "*       Sun A Cho     *" << endl;
    cout << "*					   *" << endl;
    cout << "***********************" << endl;
    cout << endl;

    // Creat instances of Questions
    Question q1;
    Question q2;
    Question q3;
    Question q4;
    Question q5;
    Question q6;

    // Set the values of the Questions instances
    q1.setValues("What does cout do?",
		 "Eject a CD",
		 "Send text to the printer",
		 "Print text on the screen", "Play 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 company", "Get 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 be 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 >= highScores.lowest()) { // dmh
	// dmh
	cout << "You got a high score!" << endl;
	cout << "Please enter your name" << endl;
	string name;
	getline(cin, name);
	highScores.add(Winnings, name);
    }
    // Print the high score list
    cout << "High Score list" << endl;
    // Notice that HighScore::write() is used both to display the scores
    // on screen, and to write them to the file.
    highScores.write(cout);	// dmh

    // Output the high score to a file
    ofstream Output_High_Scores;
    Output_High_Scores.open("High_Scores.txt");
    highScores.write(Output_High_Scores); // dmh
    Output_High_Scores.close();

    system("PAUSE");
}

// 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;
    cin.ignore();		// skip the newline
    // 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;
    }

}

void
reset()
{
    string rewrite;
    HighScore highScores;
    
    cout << "Do you want to rest the high scores?" << endl;
    cin >> rewrite;
    if (rewrite == "y") {
	highScores.reset();
	std::ofstream ofs;
	ofs.open("High_Scores.txt", std::ofstream::out | std::ofstream::trunc);
	highScores.write(ofs);
	ofs.close();
    } else if (rewrite == "n") {
	system("PAUSE");
    }
}

Hello, Dave!

this is what I have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 /*
The Great Quiz Show Game

by

Sun A Cho


*/

//Include the libraries
#include <iostream>
#include <string>
#include <fstream>

// Use the standard namespace
using namespace std;

// Declare global variables
int Guess;
int Winnings;
int ask;

// dmh
class HighScore
{
	public:
	HighScore() 
	{
		reset();
	}
	bool read(istream &is);
	bool write(ostream &os);
	unsigned lowest() 
	{
		return scores[numScores - 1];
	}
	void add(unsigned score, string &name);
	void reset();

	static constexpr size_t numScores = 5;

	//scores sorted from highest to lowest
	unsigned scores[numScores];
	// corresponding names
	string names[numScores];
};


///////// DMH - put the code for the HighScores methods here.   //////
void  HighScores()
{
	int High_Score[5];
	string High_Score_Name[5];

	High_Score[0] = 25000;
	High_Score[1] = 15000;
	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";
}


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();
};

int main()
{

	// Declare local variables
	HighScore highScores;	// dmh

	// Input the high scores from a file
	ifstream Input_High_Scores;
	Input_High_Scores.open("High_Scores.txt"); // dmh careful with the name
	highScores.read(Input_High_Scores); // dmh
	Input_High_Scores.close();		// dmh


	// Show the title screen
	cout << "***********************" << endl;
	cout << "*                     *" << endl;
	cout << "* The Great Quiz Show *" << endl;
	cout << "*                     *" << endl;
	cout << "*          by         *" << endl;
	cout << "*					   *" << endl;
	cout << "*       Sun A Cho     *" << endl;
	cout << "*					   *" << endl;
	cout << "***********************" << endl;
	cout << endl;

	// Creat instances of Questions
	Question q1;
	Question q2;
	Question q3;
	Question q4;
	Question q5;
	Question q6;

	// Set the values of the Questions instances
	q1.setValues("What does cout do?",
		"Eject a CD",
		"Send text to the printer",
		"Print text on the screen", "Play 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 company", "Get 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 be 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 >= highScores.lowest()) { // dmh
		// dmh
		cout << "You got a high score!" << endl;
		cout << "Please enter your name" << endl;
		string name;
		getline(cin, name);
		highScores.add(Winnings, name);
	}
	// Print the high score list
	cout << "High Score list" << endl;
	// Notice that HighScore::write() is used both to display the scores
	// on screen, and to write them to the file.
	highScores.write(cout);	// dmh

	// Output the high score to a file
	ofstream Output_High_Scores;
	Output_High_Scores.open("High_Scores.txt");
	highScores.write(Output_High_Scores); // dmh
	Output_High_Scores.close();

	system("PAUSE");
}

// 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;
	cin.ignore();		// skip the newline
	// 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;
	}

}

void reset()
{
	string rewrite;
	HighScore highScores;

	cout << "Do you want to rest the high scores?" << endl;
	cin >> rewrite;
	if (rewrite == "y") {
		highScores.reset();
		std::ofstream ofs;
		ofs.open("High_Scores.txt", std::ofstream::out | std::ofstream::trunc);
		highScores.write(ofs);
		ofs.close();
	}
	else if (rewrite == "n") {
		system("PAUSE");
	}
}


There are some errors with this code apparently:(
1. 'numScores' is undefined
2. missing ; before size_t
3. 'HighScore::numScores' is not a type name, static, or enumerator
4. '>=': is signed/unsignd mismatch
Last edited on
This is the new one that I came up with, but it doesn't seems to be working...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*

/*
The Great Quiz Show Game

by

Sun A Cho


*/

//Include the libraries
#include <iostream>
#include <string>
#include <fstream>

// Use the standard namespace
using namespace std;

// Declare global variables
int Guess;
int Winnings;
int ask;

// 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();
};

class Ask
{
public:
	void highScores();
	void erase();
	void output();
	void reset();
};

void output()
{
	int High_Score[5];
	string High_Score_Name[5];

	ofstream Output_High_Scores;
	Output_High_Scores.open("High_Scores.txt");

	Output_High_Scores << High_Score[0] << endl;
	Output_High_Scores << High_Score_Name[0] << endl;
	Output_High_Scores << High_Score[1] << endl;
	Output_High_Scores << High_Score_Name[1] << endl;
	Output_High_Scores << High_Score[2] << endl;
	Output_High_Scores << High_Score_Name[2] << endl;
	Output_High_Scores << High_Score[3] << endl;
	Output_High_Scores << High_Score_Name[3] << endl;
	Output_High_Scores << High_Score[4] << endl;
	Output_High_Scores << High_Score_Name[4] << endl;

	Output_High_Scores.close();

}

void high_score_erase()
{
	std::ofstream ofs;
	ofs.open("High_Scores.txt", std::ofstream::out | std::ofstream::trunc);
	ofs.close();
}

void highScores()
{
	int High_Score[5];
	string High_Score_Name[5];

	// Initialize local variables
	High_Score[0] = 25000;
	High_Score[1] = 15000;
	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";
}

void main()
{

	// Declare local variables
	int High_Score[5];
	string High_Score_Name[5];
	int Rank;

	// Initiallize 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_Score.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] = 15000;
		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 *" << endl;
	cout << "*                     *" << endl;
	cout << "*          by         *" << endl;
	cout << "*					   *" << endl;
	cout << "*       Sun A Cho     *" << endl;
	cout << "*					   *" << endl;
	cout << "***********************" << endl;
	cout << endl;

	// Creat instances of Questions
	Question q1;
	Question q2;
	Question q3;
	Question q4;
	Question q5;
	Question q6;

	// Set the values of the Questions instances
	q1.setValues("What does cout do?",
		"Eject a CD",
		"Send text to the printer",
		"Print text on the screen",
		"Play 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 company",
		"Get 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 be 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[1 - i];
			High_Score_Name[i] = High_Score_Name[1 - i];
		}
		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;
	}

	void reset();

	// Output the high score 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();
	system("PAUSE");
}

// 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;
	}
}

void reset()
{
	string rewrite;

	cout << "Type y for reset or n for no reset" << endl;
	cin >> rewrite;

	if (rewrite == "y")
	{
		int High_Score[5];
		string High_Score_Name[5];

		void erase();
		void output();


	}

	if (rewrite == "n")
	{
		system("PAUSE");
	}
}
Hello, I made a new one that is more of my level, but this code doesn't do the job (resetting the list or responding to Y or N)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
*/

/*
The Great Quiz Show Game

by

Sun A Cho


*/

//Include the libraries
#include <iostream>
#include <string>
#include <fstream>

// Use the standard namespace
using namespace std;

// Declare global variables
int Guess;
int Winnings;
int ask;

// 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();
};

class reset
{
public:
	void highScores();
	void erase();
	void output();
};

void output()
{
	int High_Score[5];
	string High_Score_Name[5];

	ofstream Output_High_Scores;
	Output_High_Scores.open("High_Scores.txt");

	Output_High_Scores << High_Score[0] << endl;
	Output_High_Scores << High_Score_Name[0] << endl;
	Output_High_Scores << High_Score[1] << endl;
	Output_High_Scores << High_Score_Name[1] << endl;
	Output_High_Scores << High_Score[2] << endl;
	Output_High_Scores << High_Score_Name[2] << endl;
	Output_High_Scores << High_Score[3] << endl;
	Output_High_Scores << High_Score_Name[3] << endl;
	Output_High_Scores << High_Score[4] << endl;
	Output_High_Scores << High_Score_Name[4] << endl;

	Output_High_Scores.close();

}

void high_score_erase()
{
	std::ofstream ofs;
	ofs.open("High_Scores.txt", std::ofstream::out | std::ofstream::trunc);
	ofs.close();
}

void highScores()
{
	int High_Score[5];
	string High_Score_Name[5];

	// Initialize local variables
	High_Score[0] = 25000;
	High_Score[1] = 15000;
	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";
}

void main()
{

	// Declare local variables
	int High_Score[5];
	string High_Score_Name[5];
	int Rank;

	// Initiallize 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_Score.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] = 15000;
		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 *" << endl;
	cout << "*                     *" << endl;
	cout << "*          by         *" << endl;
	cout << "*					   *" << endl;
	cout << "*       Sun A Cho     *" << endl;
	cout << "*					   *" << endl;
	cout << "***********************" << endl;
	cout << endl;

	// Creat instances of Questions
	Question q1;
	Question q2;
	Question q3;
	Question q4;
	Question q5;
	Question q6;

	// Set the values of the Questions instances
	q1.setValues("What does cout do?",
		"Eject a CD",
		"Send text to the printer",
		"Print text on the screen",
		"Play 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 company",
		"Get 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 be 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[1 - i];
			High_Score_Name[i] = High_Score_Name[1 - i];
		}
		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 score 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();
	system("PAUSE");
}

// 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;
	}
}

void reset()
{
	string rewrite;

	cout << "Type y for reset or n for no reset" << endl;
	cin >> rewrite;

	if (rewrite == "y")
	{
		int High_Score[5];
		string High_Score_Name[5];

		void erase();
		void output();

	}

	if (rewrite == "n")
	{
		system("PAUSE");
	}
}


Last edited on
main() must return int, not void.

Lines 43-49: You have declared a reset class, but you never use it or define the methods. Are the 3 functions that follow supposed to be the methods?

Line 81: highScores doesn't do anything because it acts upon the local variables. Local variables get destroyed when you exit the block of code where they're defined. Also, you never call it.

Line 297: reset() never gets called.

Looking at your original post, you talk about reset.exe, which implies that maybe reset is supposed to be a separate program. Is that right?
This program is so hard...
I have spent so much time in trying to figure it out, but it never works.
This program is a separate one from the original quiz show program. The program that you wrote supposedly had some errors, which I just don't get, because you are a pro.
Ah! If it's a separate program then it's almost trivial. Just create a new program that writes the following to the high_scores.txt file:
25000 Gwenyth
15000 Adam
7500 Nastasia
4000 Nicolas
2000 Dani


That's all there is to it!
OMG... I have been overthinking this now that I have figured it out! Thank you for your amazing help!!!
Topic archived. No new replies allowed.