I just learned C programming. Now, I am trying to perform looping using the goto control statement, but I just faced a problem when I use variable char.
#include <stdio.h>
char score;
int main(){
loop:
printf("Please Input Your Score : ");
scanf("%c", &score);
switch(score){
case 'A' :
printf("Nilai Anda Baik");
break;
default :
printf("Nilai Anda Salah");
goto loop;
}
return 0;
}
The problem is if I input the wrong score such as 'B', it will print "Nilai Anda Salah" and then automatically print again "Please Input Your Score: Nilai Anda Salah" one time. After that print again "Please Input Your Score: " and then I can input again the score.
I don't know why it is skipping the scanf command.