i need help on how to reset a .txt file for a game show text game

I have been writing C++ for a couple of months now using Microsoft Visual C++ 2008 Express Edition , but i am having some trouble with a text game project that i am writing. the issue is that i can not figure out how to make it so that the user can reset the high scores back to the original.

Below is the code, and thanks to those that can help.



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
/*
 
The c++ test game show
 
           by
 
      bob the giraff
 
*/
 
// Include the libraries
#include <iostream>
#include <string>
#include <fstream>
 
//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 c++ test game show *" << endl;
   cout << "*                        *" << endl;
   cout << "*           by           *" << endl;
   cout << "*                        *" << endl;
   cout << "*     bob the giraff     *" << endl;
   cout << "*                        *" << endl;
   cout << "**************************" << endl;
   cout << endl;

      // Create instances of Question
   Question q1;
   Question q2;
   Question q3;
   Question q4;
   Question q5;
   Question q6;
   Question q7;
   Question q8;
   Question q9;
 
   // Set the values of the Question instances
   q1.setValues ("What does cout do?",
              "Eject a CD so you don't have to press the button to do so",
              "Count for you becuase your lazy and you don't want to",
              "Print the text in it on to the screen",
              "It's a cheat for my video game so i always win",
              3,
              4500);

    q2.setValues ("What is C++? (C plus-plus)",
              "A math expression",
              "A computer programming language",
              "A new texting abbreviation",
              "Some weird alien language",
              2,
              2500);
	q3.setValues ("when compiling a project what does the code turn into?",
              "A completed project, duh",
              "A monster that eats my files",
              "more work for me",
              "1's and 0's",
              4,
              4000);
	q4.setValues ("What is the first project you are most likley to make using C++?",
              "Some awsome, super complicated game",
              "The hello world project",
              "A blank black box",
              "A MS-DOS file",
              2,
              3000);
	q5.setValues ("How do you write in C++?",
              "Very carefully",
              "With your feet (i'm a weird person)",
              "With a computer, C++ software, some C++ code, and keyboard",
              "Write some random stuff that you hope is code and wing it",
              3,
              2500);
	q6.setValues ("What are you doing right now?",
              "Playing a quiz show writen by Mitchell Eblin",
              "surfing the web",
              "Whatever the **** you want (you think your Bam Margera in Viva La Bam)",
              "Rotting your brain",
              1,
              2000);
	q7.setValues ("What does it take to write a project in C++?",
              "A computer, duh",
              "knowledge on how to do it",
              "How am i supposed to know? I'm no computer genius",
              "Help from another planet",
              2,
              3500);
	q8.setValues ("Which namespace is standard in C++?",
              "An average box at the top of my school paper for my name",
              "The universe (yep i'm right 'cause know my astrology)",
              "Myspace, well at least it is mine",
              "STD (and as you think about it you chuckle slightly)",
              4,
              2500);

	q9.setValues ("(!BONUS!)What library do you HAVE TO HAVE to make any C++ program?(!10,000 POINTS!)",
              "The C++ iostream library",
              "The C++ universal library",
              "The C++ main library",
              "The C++ coding library",
              1,
              10000);
 
   // Ask the questions
   q1.askQuestion ( );
   q2.askQuestion ( );
   q3.askQuestion ( );
   q4.askQuestion ( );
   q5.askQuestion ( );
   q6.askQuestion ( );
   q7.askQuestion ( );
   q8.askQuestion ( );
   q9.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 ( );

   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;
   }
}
please highlight(bold, italicize) the areas you are having trouble and what they use, e.g. certain functions, a line of code. helps us read it easier and help you faster. Thanks!
well, the thing is i am trying to make it so that the user can reset the highscore, but my teacher didn't say how or where to do it.
Opening an ofstream with ios::trunc flag will explicitally tell the stream to be cleared
the thing is that that will not work, my teacher said that it has to ask the user if they want to reset the highscore and put either a "y" or a "n". i

t should look like the photo in the below link

http://www.flickr.com/photos/bob_the_giraff/7108455303/in/photostream
create a function that reopens the file using ofstream like so:
1
2
3
4
5
6
7
ofstream ofile( "train.txt", ios::out );
if (!ofile.is_open())
{
std::cout << "OpenFile train.txt Errors!" << std::endl;
}
ofile.close();


tell me how it goes
it did reset the .txt file, but is there a way to have the user control if it resets or not?
put the code into a function, every time the user types yes close the existing file and re-open the file again.
we apear to be taking the same C++ class, personally i couldnt figure that out, i simply submited the quiz.
Topic archived. No new replies allowed.