English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hey i have a little problem with this code, when i compile with visual c++ it displays error C2046, what might be the problem?
Thanks!
#include
#include
char campo[50],gato[10],teatro[4][8];
int x=0,tiro,w=1,acertado=0,fallado=0,hundido=0,bol,ctr[8],num[20],y,z,j,menu=0;
-------------------------declaring functions------------------
main()
{ do
{
scanf("%d",&menu);
switch(menu);
{ case 1:
{ submarino();
break;
}
case 2:
{ juego_gato();
break;
}
case 3:
{ venta_teatro();
break;
}
case 4:
{ sort();
break;
}
case 5: return 0;
case 5: return 0;
default: printf("Opcion invalida, vuelve a intentar.");

}
}
while(menu!=500);
Any help will be apreciated! Thanks!

2007-05-14 11:28:22 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Did you mean to define "case 5" twice? Also, get rid of the semicolon (;) after "switch(menu);".

2007-05-14 11:37:32 · answer #1 · answered by Michael JB 3 · 0 0

Error C2046 states "The keyword case can appear only in a switch statement." which is probably because the have case 5 twice and also getting rid of the semicolon after switch will help.

2007-05-14 12:06:12 · answer #2 · answered by serg_et 2 · 0 0

your case statements have brackets and you dont need them.

change
case 2:
{ juego_gato();
break;
}

to
case 2:
juego_gato();
break;

same for all of them

as others said, you can only have 1 case 5

2007-05-15 01:07:36 · answer #3 · answered by justme 7 · 0 1

fedest.com, questions and answers