Hi,
I am trying to write a program that asks the user to enter a number between 0 and 9. I also have to validate the input. That part works just fine. The problem comes in when they enter something other than 0-9. The error message displays and the prompt appears again which asks for them to enter a number between 0-9. So, the validation works like a charm. For whatever reason, however, when I tested the program I couldn't type anything at this point to input something else. Any ideas what is causing that?
Here is the code:
Code:
#include <stdafx.h>
int main ()
{
int user_input;
printf("Please enter a number between 0 and 9: ");
scanf("%d", &user_input);
if (user_input < 0 || user_input > 9)
{
printf("Error: That is not a valid entry!\n");
printf("Please enter a number between 0 and 9: ");
scanf("%d", &user_input);
}
else printf("Thank you! You selected %d\n", user_input);
return 0;
}