+ 5
Need a little help with switch
This is my program: #include <stdio.h> int main() { int i = 0; switch (i) { case '0': printf("IXEL"); break; case '1': printf("FOR"); break; default: printf("TRAINING"); } return 0; } shouldn't asnwer be IXEL?? answer is TRAINING Why???
4 RĂ©ponses
+ 4
Itâs because of data types. â0â and 0 are not the same thing, â0â means a character.
Here is the corrected code:
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case 0: printf("IXEL");
break;
case 1: printf("FOR");
break;
default: printf("TRAINING");
}
return 0;
}
+ 1
'0' is a char data type so to correct it you should write case 0: and case 1: