I tried to have defensive programming having input as an integer but the program would go into infinite loop if I entered a character. I then switched to having input as a character, but it does the loop twice. Once for the wrong character and once for the end of line keystroke.
Is there any way to get the loop, just once?
code:
int main(int argc, char *argv[])
{
char choice='5';
while (choice != '1' && choice !='2' && choice !='3' && choice!='4' && choice!='0')
{
printf("Parakalw epilekste ena apo ta parakatw\n\n");
printf("1.\tKafe 1.5 euro\n");
printf("2.\tKafe me gala 1.8 euro\n");
printf("3.\tSokolata 2.1euro\n");
printf("4.\tSokolata me gala 2.4 euro\n");
printf("0.\tExodos\n\n");
printf("parakalw eisagete thn epilogh sas: ");
scanf("%c",&choice);
}
system("PAUSE");
return 0;
}