Hi, i have a menu program, when i select option C and after going back to the menu, if i enter a vaild option it will say its invalid. However if i select option a or b and then enter an invalid option and then enter a valid option it wont say the valid option is invalid. ?
Code:
char menu_option;
int count, number;
do
{
printf ("\n\nYou have four choices.\n");
printf ("Enter a to print your name\n");
printf ("Enter b to print your tutorial time\n");
printf ("Enter c to input a number between 1 and 50\n");
printf ("Enter q to quit.\n");
scanf ("%c%*c", &menu_option);
menu_option = tolower(menu_option);
switch( menu_option )
{
case 'a':
printf("You have selected option A\n\n");
break;
case 'b':
printf("You have selected option B\n\n");
break;
case 'c':
printf("You have selected option C\n");
printf("Please enter a number between 1 and 50:\n");
scanf("%i", &number);
if ( number < 1 || number > 50)
printf("Invalid number\n\n");
else
for (count = 0; count <= number; ++count){
printf("%i,", count);
}
break;
case 'q':
break;
default:
printf("You have not selected a valid option\n\n");
}
} while (menu_option != 'q');
Comment