Switch statement
Oct 15, 2013 at 7:22am UTC
My switch statement is not working properly. It keeps giving me an error wherein line 46 and 48 are not within a switch statement. I've quadrupled check already.
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
do {
scanf("%d" , choice2);
switch (choice2){
case 1: for (j=0;j<strlen(word);j++){
if (strcmp(variable.board[(r*2)+2+(2*j)][c+2], 32)!=0){
if (strcmp(variable.board[(r*2)+2+(2*j)][c+2],word[j]!=0){
m = 1;
printf("Your word doesn't not fit the board!\n" );
break ;
}
}
}
if (m==0){
for (j=0;j<strlen(word);j++){
variable.board[(r*2)+2+(2*j)][c+2] = word[j+1];
}
for (j=1;j<strlen(word);j++){
if (strcmp(variable.players[variable.p].tiles[j], word[j])==0){
variable.players[variable.p].tiles[j] = 0;
}
}
}
return variable;
break ;
case 2: for (j=0;j<strlen(word);j++){
if (strcmp(variable.board[(r*2)+2][c+2+j], 32)!=0){
if (strcmp(variable.board[(r*2)+2][c+2+j],word[j]!=0){
m = 1;
printf("Your word doesn't not fit the board!\n" );
break ;
}
}
}
if (m==0){
for (j=0;j<strlen(word);j++){
variable.board[(r*2)+2+(2*j)][c+2+j] = word[j+1];
}
for (j=1;j<strlen(word);j++){
if (strcmp(variable.players[variable.p].tiles[j], word[j])==0){
variable.players[variable.p].tiles[j] = 0;
}
}
}
return variable;
break ;
case 3:
break ;
default : printf("\nInvalid Input!\n" );
}
}while (choice2!=2 && choice2!=1 && choice2!=3);
Last edited on Oct 15, 2013 at 7:30am UTC
Oct 15, 2013 at 7:50am UTC
Count the parentheses on line 27.
Oct 15, 2013 at 8:02am UTC
Thanks!
Topic archived. No new replies allowed.