Please help! I keep getting errors with my do while loop

I keep getting while loop errors in MSVS 2013.
The errors are intellisense expected a while on lines 100 and 103 and error C2059 expected a '}' on lines 100 and 102. Please help me. I'm so lost.

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
  /* -----------------------------------------------------------------------------
FILE:              Math_Testor.CPP 
DESCRIPTION:        
COMPILER:          Tell another programmer what development tools were used
to build the program 
NOTES:             Put other information here ... 
MODIFICATION HISTORY: Author                  Date               Version
                     ---------------         ----------         --------------
                     Kendelle Innis           2016-11-04             1 
----------------------------------------------------------------------------- */

#include <iostream>
#include <cmath>
#include <string>
#include <ctime>
#include <cstdlib>


using namespace std;

char choice;
void addition(int mod);
void subtraction(int mod);
void mainMenu();
void difficultyMenu();


int main()
{
	srand(time(NULL));
	do
	{
		mainMenu();

		switch (choice)
		{
		case 'a':
			do
			{
				difficultyMenu();

				switch (choice)
				{
				case '1':
					addition(9);
					break;
				case '2':
					addition(99);
					break;
				case '3':
					addition(999);
					break;
				case '4':
					addition(9999);
					break;
				case '5':
					addition(99999);
					break;
				default:
					cout << choice << " is not a valid entry. Please try again" << endl;
					while (choice != 6)
					{
						mainMenu();
					}
				}
				

		case 'b':
			difficultyMenu();

			switch (choice)
			{
			case '1':
				subtraction(9);
				break;
			case '2':
				subtraction(99);
				break;
			case '3':
				subtraction(999);
				break;
			case '4':
				subtraction(9999);
				break;
			case '5':
				subtraction(99999);
				break;
			case '6':
				break;
			default:
				cout << choice << " is not a valid entry. Please try again" << endl;

			}

			while (choice = 'q');
			{
				return 0;
			}
			}

		}
	}
}

void mainMenu()
{
	cout << "            Arithmetic Practice Program                 " << endl;
	cout << "Hello, and welcome to the Math Skills Practice Program." << endl;
	cout << "This program allows you to practice your math skills." << endl;
	cout << "Choose what you want to practice in the menu shown below" << endl;
	cout << "--------------------------------------------------------" << endl;
	cout << "             ARITHMETIC PRACTICE PROGRAM              " << endl;
	cout << "                     MAIN MENU                        " << endl;
	cout << "--------------------------------------------------------" << endl;
	cout << "                 a. Addition                            " << endl;
	cout << "                 b. Substraction                        " << endl;
	cout << "                 c. Multiplication                      " << endl;
	cout << "                 d. Division                            " << endl;
	cout << "                 q. Quit the program                    " << endl;
	cout << "--------------------------------------------------------" << endl << endl;
	cout << " Enter your choice [a, b, c, d or q]:";
	cin >> choice;
	system("cls");
}
void difficultyMenu()
{
	cout << "Please select difficulty" << endl;
	cout << "1. 0-9" << endl;
	cout << "2. 0-99" << endl;
	cout << "3. 0-999" << endl;
	cout << "4. 0-9999" << endl;
	cout << "5. 0-99999" << endl;
	cout << "6. Return to Main Menu" << endl;
	cout << "Please select 1-6: ";
	cin >> choice;
	system("cls");
}
void addition(int mod)
{
	int answer = rand() % 3;
	int random1, random2;
	char ans;
	random1 = 1 + (rand() % mod);
	random2 = 1 + (rand() % mod);
	cout << "What is " << random1 << " + " << random2 << " = ?" << endl << endl;
	

	int percentage = rand() % 10;
	int corrt = random1 + random2;
	int mc_answers[3];

	if (percentage < 80)
	{

		mc_answers[0] = corrt;
		for (int i = 1; i<3; i++)
		{
			mc_answers[i] = rand() % mod;
		}

		  
		int temp = mc_answers[answer];
		mc_answers[answer] = corrt;
		mc_answers[0] = temp;
	}
	else
	{
		for (int i = 0; i<3; i++)
		{
			mc_answers[i] = rand() % mod;
		}
	}
	cout << "a. " << mc_answers[0] << endl;
	cout << "b. " << mc_answers[1] << endl;
	cout << "c. " << mc_answers[2] << endl;
	cout << "d. None of the Above " << endl;

	cout << "Please select an answer [a-d]: ";
	cin >> choice; 
		if (choice == random1 + random2)
		{
			cout << "Congratulations. That is correct." << endl;
		}
		else
		{
			cout << "That is incorrect.";
		}
}
void subtraction(int mod)
{
	int random1, random2;
	char ans;
	random1 = 1 + (rand() % mod);
	random2 = 1 + (rand() % mod);
	cout << "What is " << random1 << " + " << random2 << " = ?" << endl << endl;
	cout << "Please select an answer [a-d]" << endl;

	int percentage = rand() % 10;
	int corrt = random1 - random2;
	int mc_answers[3];

	if (percentage < 80)
	{

		mc_answers[0] = corrt;
		for (int i = 1; i<3; i++)
		{
			mc_answers[i] = rand();
		}

		int answer = rand() % 3;
		int temp = mc_answers[answer];
		mc_answers[answer] = corrt;
		mc_answers[0] = temp;
	}
	else
	{
		for (int i = 0; i<3; i++)
		{
			mc_answers[i] = rand();
		}
	}
	cout << "a. " << mc_answers[0] << endl;
	cout << "b. " << mc_answers[1] << endl;
	cout << "c. " << mc_answers[2] << endl;
	cout << "d. None of the Above " << endl;


}
You have the starts of do..while loops on lines 31 and 38, but there's only one while on line 95 while (choice = 'q');, which doesn't seem to match up. (Also - I think you want the equality operator == there, not assignment =.)
Hi! Thank you for the response. I do have a while statement on line 59 however. Thank you for pointing out the assignment operator btw. So I'm still not sure why I would get these errors because I have do have a while statement on line 59
Sorry I missed that earlier while. That while seems to be part of the default case of the switch statement.
1
2
3
4
while (choice != 6)
{
mainMenu();
}



I think this is what the code is trying to do with the nested loops and switches? Outer do..while controls the main menu of math options until they choose to quit the program, inner do..whiles control the difficulty submenu for each math type until they choose to stop working on that math type.

(I've pulled out the interior code of the cases and made separate choice variables local to main instead of a single global choice, assuming the menu functions return a value.)

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
int main()
{
	srand(time(NULL));
	char arithmeticchoice;
	int difficultychoice;

	do
	{
		arithmeticchoice = mainMenu();

		switch (arithmeticchoice)
		{
    		case 'a':
    		
    			do{
    				difficultychoice = difficultyMenu();
    
    				switch (difficultychoice)
    				{
    				 // cases				
    				}
    			
    			}(while difficultychoice != 6) // break out of this loop if they want to stop with addition)	

    			break;
    
    		case 'b':
    		
    		    do{
    			    difficultychoice = difficultyMenu();
    
    			    switch (difficultychoice)
    			    {
    			      // cases
    			    }
    			
    			}(while difficultychoice != 6) // break out of this loop if they want to stop with subtraction)

    			break;

            //other cases for multiplication and division
            
		} // end switch on arithmetic choice
		
	}while (arithmeticchoice != 'q'); // break out of this loop if they want to quit program
	
	
    return 0;
    
}// end main 

Topic archived. No new replies allowed.