A function to accumulate total correct

I might have confused myself trying to figure out to bring this program together. I made quite a few functions for code I thought necessary. Now, I'm trying to figure out how to grab the total correct of the user depending on the selection and number of questions, and add it to a function so it accumulates the total correct, gets called at the end to display to the user.
Here is pretty much all of my program, and please I want all kinds of opinions that can be added for detail. If there is something you would also do differently please throw it out there so I can have an advantage of knowing different ways of doing something.

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
324
325
326
327
328
329
330
331
// Function prototypes
void displayWelcome(std::string);
void displayMenu();
int getSelection();
void displayQuestions();
int getQuestions();
int specifyQuestions();
void addition(int, int);
void subtraction(int, int);
void multiplication(int, int);
void division(int, int);
void getAnswer();
//int NumberCorrect();
//void saveFile(ofstream &outFile);
void clearScreen();


int main()
{

	// Create a handle to the computer screen
	HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);

	// Using declerations for cout, cin, and endl
	using std::cout;
	using std::cin;
	using std::endl;
	std::string name,
				setColor,
				saveResults;
	std::stringstream output;
	int num1, 
		num2, 
		answer,
		count = 1,
		numberOfQuestions = 0,
		selection = 0,
		selectColor = 0,
		correctCount = 0;

	// Define file stream object
	std::ofstream outFile;
	// Open the file
	outFile.open("D:\\test.txt");
	


	cout << "Enter your name: ";
		getline(std::cin, name); // Reads entire line of input

	cout << '\n' << name << ",\nWould you like to set the color, Y or N (Default is White)? ";
	cin >> setColor;

	if (setColor == "Y" || setColor == "y") {
		cout << "1. Blue" << endl;
		cout << "2. Green" << endl;
		cout << "3. Aqua" << endl;
		cout << "4. Red" << endl;
		cout << "5. Purple" << endl;
		cout << "6. Yellow" << endl;
		cout << "7. Bright White" << endl;
		cin >> selectColor;
	}
	else if (setColor == "N" || setColor == "n")
		SetConsoleTextAttribute (screen, 7);

	switch (selectColor) {
		case 1: SetConsoleTextAttribute (screen, 1);
			break;
		case 2: SetConsoleTextAttribute (screen, 2);
			break;
		case 3: SetConsoleTextAttribute (screen, 3);
			break;
		case 4: SetConsoleTextAttribute (screen, 4);
			break;
		case 5: SetConsoleTextAttribute (screen, 5);
			break;
		case 6: SetConsoleTextAttribute (screen, 6);
			break;
		case 7: SetConsoleTextAttribute (screen, 15);
	}

	displayWelcome(name);
	
	// Initialize random seed
	srand( time(0) );


	do {
		if (count > 1)
			clearScreen();

		displayMenu();
		selection = getSelection();
		if (selection == 5)
			break;

		displayQuestions();
		numberOfQuestions = getQuestions();
		switch (numberOfQuestions) {
			case 1: numberOfQuestions = 5;
				break;
			case 2: numberOfQuestions = 10;
				break;
			case 3: numberOfQuestions = 15;
				break;
			case 4: numberOfQuestions = 20;
				break;
			case 5: numberOfQuestions = specifyQuestions();
				break;
			case 6: std::cout << "Not ready" << std::endl;
				break;
			case 7: std::cout << "Not ready" << std::endl;
		}

		for (int count = 1; count <= numberOfQuestions; count++) {
			num1 = rand() % 50 + 1;
			num2 = rand() % 50 + 1;

			// call swap function if num2 is bigger
			if (num1 < num2)
				std::swap(num1, num2);

			// Depending on selection, do that Math problem
			switch (selection) {
				case 1: addition(num1, num2);
					break;
				case 2: subtraction(num1, num2);
					break;
				case 3: multiplication(num1, num2);
					break;
				case 4: division(num1, num2);
			}
		
			// Prepare all questions if correct or wrong, for output
			/*output << num1 << " + " << num2 << " = " << answer 
					 << ((num1 + num2 == answer) ? " Correct" : " Wrong") << endl;*/

		} // For loop for number of questions
		
		count++;
	} while (selection != 5);

		if (selection != 5) {
			cout << '\n' << name << " you have " << correctCount << "/" << numberOfQuestions 
				<< " Correct.\n" << endl;
			// Ask user to save to file or not
			cout << "Save to a file, Y or N?" << endl;
			cin >> saveResults;
		}

		// Write score to file if user decides
		if (saveResults == "yes" || saveResults == "Yes" || saveResults == "y" || saveResults == "Y")
			outFile << output;

		// Close the file
		outFile.close();


	if (selection == 5)
		cout << "\nThank you for taking the Math Quiz!\nBye Bye " << name << endl;

	// Set screen color back to default
	SetConsoleTextAttribute (screen, 7);

	return 0;
}

void displayMenu()
{
	std::cout << "\nMake your Math Quiz selection: " << std::endl;
	std::cout << "[1] (+) Addition" << std::endl;
	std::cout << "[2] (-) Subtraction" << std::endl;
	std::cout << "[3] (*) Multiplication" << std::endl;
	std::cout << "[4] (/) Division" << std::endl;
	std::cout << "[5] Quit the Math Quiz" << std::endl;
}

int getSelection()
{
	int selection = 0;

	std::cin >> selection;

	while ((selection < 1) || (selection > 5)) {
		std::cout << "!!ERROR!!" << std::endl;
		displayMenu();
		std::cin >> selection;
	}

	return selection;
}

void displayQuestions()
{
	std::cout << "Select how many questions you want on the Math Quiz" << std::endl;
	std::cout << "[1] 5" << std::endl;
	std::cout << "[2] 10" << std::endl;
	std::cout << "[3] 15" << std::endl;
	std::cout << "[4] 20" << std::endl;
	std::cout << "[5] Specify how many you want (Min = 1, Max = 20)" << std::endl;
	std::cout << "[6] Randomly generate number of questions" << std::endl;
	std::cout << "[7] Go back to the Math Quiz selection window" << std::endl;
}

int getQuestions()
{
	int questions = 0;
	std::cin >> questions;

	while ((questions < 1) || (questions > 7)) {
		std::cout << "!!ERROR!!" << std::endl;
		displayQuestions();
		std::cin >> questions;
	}

	return questions;
}

int specifyQuestions()
{
	int questions = 0;

	std::cout << "How many would you like?  ";
	std::cin >> questions;

	while (questions < 1 || questions > 20) {
		std::cout << "That is not in the range.  Select from 1-20 questions." << std::endl;
		std::cout << "How many would you like?  ";
		std::cin >> questions;
	}

	return questions;
}

void addition(int num1, int num2)
{
	// Output the problem
	std::cout << '\n' << std::setw(4) << num1 << std::endl; 
	std::cout << "+" << std::setw(3) << num2 << std::endl;
	std::cout << "-----" << std::endl;
	getAnswer();
}

void subtraction(int num1, int num2)
{
	// Output the problem
	std::cout << '\n' << std::setw(4) << num1 << std::endl; 
	std::cout << "-" << std::setw(3) << num2 << std::endl;
	std::cout << "-----" << std::endl;
	getAnswer();
}

void multiplication(int num1, int num2)
{
	// Output the problem
	std::cout << '\n' << std::setw(4) << num1 << std::endl; 
	std::cout << "*" << std::setw(3) << num2 << std::endl;
	std::cout << "-----" << std::endl;
	getAnswer();
}

void division(int divisor, int dividend)
{
	int multiplier;

	divisor = rand() % 30 + 1;
	multiplier = rand() % 20 + 1;
	dividend = divisor * multiplier;

	// Output the problem
	std::cout << '\n' << "  _____" << std::endl;
	std::cout << std::setw(2) << divisor << ")" << dividend << std::endl;
	getAnswer();
}

void getAnswer()
{
	int answer;
	std::cin >> answer;

	// Some exception handling
}

int NumberCorrect()
{
	
}

/*void saveFile(ofstream &outFile)
{
	
}*/

void clearScreen()
{

  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }


Some things are still being constructed, my main focus is the NumberCorrect function.
Topic archived. No new replies allowed.