mrleo mrleo - 1 month ago 30
C Question

error: expected ‘;’ before ‘printf’ C

hello=) with this following code i get the exception
error: expected ‘;’ before ‘printf’

#include <stdlib.h>
#include <stdio.h>

int main() {
int i;
scanf("%i", &i);
for(int i=0 ; i<10; i++){

if(i==1) printf("one");

else if(i==2) printf("two");

else if(i==3) printf("three");

else if(i==4)printf("four");

else if(i==5)printf("five");

else if(i==6) printf("six");

else if(i==7) printf("seven");

else if(i==8)printf("eight");

else(i>9) printf("even"+"/n"+"odd");
}
return 0;
}


Can i sum up this code into a sorter form ? And why do i get this exeption?
thank you all

Answer

Add some brackets "{}". Code will looks better and will work.

if(expression) {

} elseif(expression) {

} elseif(expression) {

} else {

}
PS. I know it will better. If this text be comment. But I don't have points reputation yet :(

PS2. @Myst if code will have 9. Code don't printf anything.