Ello. I just made a program with 4 choices at a menu. However, if I enter a decimal like "1.5" the program just loops over and over. I'm not really sure how to I guess "deny" a decimal value, I've tried a few things but they didn't work. Here's my code:
Code:
int menu()
{
printf("Please enter your choice from one of the following options.\n");
printf("1. Play the guessing game.\n");
printf("2. Play the square game.\n");
printf("3. View your current score.\n");
printf("4. Quit.\n");
while(1)
{
int choice = 0;
scanf("%d", &choice);
if(choice < 1 || choice > 4)//If the user-inputted choice is not a correct value on the menu, return an error message.
{
printf("Sorry, that is not a valid choice. Please try again.\n");
}
else
{
return choice;
break; //If the user-inputted choice is a correct value on the menu, break out of the loop.
}
}
}