PLease I need help (knowledge of switches and functions)

The message log keeps telling me that I am incorrectly using the switch statements. it says that I have incorrect breaks and cases. I don't' think so and so I don't know what to do. I cut my code up in order to see the jist of it. any help would be greatly appreciated! I should have gotten this by now.

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
  #include <iostream>
#include <stdio.h>
#include <ctype.h>
#include<time.h>
#include<math.h>


using namespace std;




	
	

 signed int MathOp_C (signed int  b ) 

{	
	signed int  x,y;
	signed int  guess;
	signed int  pass;
	
	srand((unsigned)time(0));
	x=rand()%(10^(b-1));
		y= rand()%(10^(b-1));

	cout<< "--------Multiplication-------\n\n"<<endl;
	cout<<endl;
	cout<<endl;
	cout<< x <<" X "<< y<< " = \n    Enter Answer"<<endl; 
	cin>> guess;
	
	
	while (guess = (x*y))
		
	{	pass = 1;}
	while  (guess != (x*y))
	{pass=2;}

	return (pass);

}





 void Outstatment (signed int  j)
{
	signed int  ran;
	
	while (j!=0)
	{
	
switch   (j)

	{
	
	
	case 1: 
		{

	
		switch (ran)

		{
			case 1:   cout <<"  way to go!!! "<<endl;
			break;
			case 2:   cout <<"  You sure knocked that one outta there! "<<endl;
			break;
			case 3:   cout << "  Whoa!!!  Wait..  Who the heck ARE you again?  "<< endl;
			break; 
			case 4:	  cout <<  "  Your Not too bad at all..  "<<endl;
			break;
		
			default: cout<< "  why am I seeing this?"<<endl;
		}
		
		} break;
		
		

	case 2: 
		
		{
			srand((unsigned)time(0));
			ran= rand()%5;

		switch (ran)

		
		{
			case 1:   cout <<"  So Close!! :).. "<<endl;
			break;
			case 2:   cout <<" Incorrect  "<<endl;
			break;
			case 3:   cout << "  Think about it.  "<< endl;
			break; 
			case 4:	  cout <<  " At first, if you do not succeed..  "<<endl;
			break;

			default: cout<< "  why am I seeing this?"<<endl;
		}
		
		} 
		break;
}
		 
			default: cout<< " what it this ?" <<endl;
	}
	

}




int main()
{
	signed int op;
    signed int level;
	char play ;
	signed int  a;

	cout<< "Do you wanna play the game " <<endl;
    cin >> play;
    play = tolower(play);
   
	do
	{
		

	switch (play) //this loop won't run as (my_int1>=0) is false!
    {
	
	
	case 'y':





		{
			
			
			
		  cout << "Welcome to the math tutor !" << endl;
          cout << "Which math operation would you like to train?" << endl;
		  
          cout << "=( Enter 1 for Addition -=\n" << endl;
		  cout << "=( Enter 2 for Subtaction-=\n" << endl;
		  cout << "=( Enter 3 for Multiplication-=\n" << endl;
		  cout << "=( Enter 4 for Divsion-=\n" << endl;

		  
		  cin  >> op;
		  
		  

		  cout << "At what game level do you wish to train at?" << endl;
		  cout << "=( Enter 1 for 1 digits-=\n" << endl;
		  cout << "=( Enter 2 for two-=\n" << endl;
		  cout << "=( Enter 3 for three-=\n" << endl;
		  cout << "=(feel free to test the programs limits!" << endl;

		  cin >> level;
		 



		  do
		  {


		  switch (op)
		{
			case 1: 
					MathOp_A (level);
			break;
		
			case 2:	 
					MathOp_B (level);
			break;
		
			case 3:	
					MathOp_C (level);
			break;

	    	case 4:  
					MathOp_D (level);
			break;

			default: cout<<"??"<<endl;
		}


		  }
		  while (level != 0)
		
 
	
	





		  Outstatment(op);
          
          cout << "WOULD YOU LIKE TO PLAY AGAIN?(y/n): ";
          cin >>play;
		  cout << endl;}

	
	
	
	}
	
		  
	
	
	
	break;

	





case 'n':	
	{
				cout<<"have a good day!"<<endl;
				break;
	default:  cout<< "okay bye."<<endl;
	}
	break;
    default:   cout<<"hahha"<<endl;
		} 
		}while (play!=0)
    system("pause");
    return 0;
}
main.cpp: In function 'int MathOp_C(int)':
main.cpp:34:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  while (guess = (x*y))
                     ^
main.cpp: In function 'void Outstatment(int)':
main.cpp:109:4: error: case label not within a switch statement
    default: cout<< " what it this ?" <<endl;
    ^
main.cpp: In function 'int main()':
main.cpp:178:21: error: 'MathOp_A' was not declared in this scope
      MathOp_A (level);
                     ^
main.cpp:182:21: error: 'MathOp_B' was not declared in this scope
      MathOp_B (level);
                     ^
main.cpp:190:21: error: 'MathOp_D' was not declared in this scope
      MathOp_D (level);
                     ^
main.cpp:208:5: error: expected ';' before 'Outstatment'
     Outstatment(op);
     ^
main.cpp:231:1: error: case label ''n'' not within a switch statement
 case 'n': 
 ^
main.cpp:235:2: error: case label not within a switch statement
  default:  cout<< "okay bye."<<endl;
  ^
main.cpp:238:5: error: case label not within a switch statement
     default:   cout<<"hahha"<<endl;
     ^
main.cpp:240:3: error: expected 'while' before '}' token
   }while (play!=0)
   ^
main.cpp:240:3: error: expected '(' before '}' token
main.cpp:240:3: error: expected primary-expression before '}' token
main.cpp:240:3: error: expected ')' before '}' token
main.cpp:240:3: error: expected ';' before '}' token
main.cpp:123:14: warning: unused variable 'a' [-Wunused-variable]
  signed int  a;
              ^
main.cpp: At global scope:
main.cpp:240:4: error: expected unqualified-id before 'while'
   }while (play!=0)
    ^
main.cpp:242:5: error: expected unqualified-id before 'return'
     return 0;
     ^
main.cpp:243:1: error: expected declaration before '}' token
 }
 ^

Let's take this one at a time.
main.cpp:34:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  while (guess = (x*y))
                     ^
You probably meant while (guess == (x*y)) here.

main.cpp: In function 'void Outstatment(int)':
main.cpp:109:4: error: case label not within a switch statement
    default: cout<< " what it this ?" <<endl;
    ^
The indentation here is really bad, so it's hard to see, but your default: case is outside of your switch statement.
You probably just misplaced/added an extra } or something.

main.cpp: In function 'int main()':
main.cpp:178:21: error: 'MathOp_A' was not declared in this scope
      MathOp_A (level);
                     ^
main.cpp:182:21: error: 'MathOp_B' was not declared in this scope
      MathOp_B (level);
                     ^
main.cpp:190:21: error: 'MathOp_D' was not declared in this scope
      MathOp_D (level);
                     ^
I suppose you probably have these functions defined in your code, but you deleted them in order to save space when you posted it.

main.cpp:208:5: error: expected ';' before 'Outstatment'
     Outstatment(op);
     ^
You missed a semicolon at the end of your while (level != 0) (line 198).

main.cpp:231:1: error: case label ''n'' not within a switch statement
 case 'n': 
 ^
main.cpp:235:2: error: case label not within a switch statement
  default:  cout<< "okay bye."<<endl;
  ^
main.cpp:238:5: error: case label not within a switch statement
     default:   cout<<"hahha"<<endl;
     ^
Once again, these case values are outside of your switch.
In this case, the first default: case is actually inside your case 'n': block!

main.cpp:240:3: error: expected 'while' before '}' token
   }while (play!=0)
   ^
main.cpp:240:3: error: expected '(' before '}' token
main.cpp:240:3: error: expected primary-expression before '}' token
main.cpp:240:3: error: expected ')' before '}' token
main.cpp:240:3: error: expected ';' before '}' token
main.cpp:123:14: warning: unused variable 'a' [-Wunused-variable]
  signed int  a;
              ^
main.cpp: At global scope:
main.cpp:240:4: error: expected unqualified-id before 'while'
   }while (play!=0)
    ^
main.cpp:242:5: error: expected unqualified-id before 'return'
     return 0;
     ^
main.cpp:243:1: error: expected declaration before '}' token
 }
 ^
You put one too many closing braces (}) at the end, so this part:
240
241
242
243
}while (play!=0)
    system("pause");
    return 0;
}
is actually outside of main (that first closing brace there on line 240 ends the main function).

Again, some indentation would make these errors much clearer.
Topic archived. No new replies allowed.