Monday, May 24, 2010

I have a problem with my C++ code (SWITCH)?

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%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


char campo[50],gato[10],teatro[4][8];


int x=0,tiro,w=1,acertado=0,fallado=0,hundid...


-------------------------declaring functions------------------


main()


{ do


{


scanf("%d",%26amp;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!

I have a problem with my C++ code (SWITCH)?
Did you mean to define "case 5" twice? Also, get rid of the semicolon (;) after "switch(menu);".
Reply: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
Reply: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.


No comments:

Post a Comment