error: case label not within a switch statement
Hello everyone,
I just have an error in my switch. I checked online for an answer, but I didn't find one :(.
Here is the code:
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
|
int choixOperation(0);
cin >> choixOperation;
switch (choixOperation)
case 0:
return 0;
break;
case 1:
add(frac1, frac2);
cout << frac1;
break;
case 2:
sub(frac1, frac2);
cout << frac1;
break;
case 3:
mult(frac1, frac2);
cout << frac1;
break;
case 4:
div(frac1, frac2);
cout << frac1;
break;
default:
cout << "Type in a right number" << endl;
break;
|
And my error is
error: case label not within a switch statement |
The error is located here at the 28th line.
Help!
Cases need to be enclosed in a set of braces, like so:
1 2 3 4 5
|
switch( ... )
{
case:
// ...
}
|
Wazzak
Try wrapping that switch statement with curly brackets. switch (choixOperation) { ...... }
Greetings,
It should be
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
|
switch (choixOperation)
{
case 0:
return 0;
break;
case 1:
add(frac1, frac2);
cout << frac1;
break;
case 2:
sub(frac1, frac2);
cout << frac1;
break;
case 3:
mult(frac1, frac2);
cout << frac1;
break;
case 4:
div(frac1, frac2);
cout << frac1;
break;
default:
cout << "Type in a right number" << endl;
break;
}
|
How stupid I am!
How could I forget them!
Thank you anyway ;)
Topic archived. No new replies allowed.