I need to make sure the user enters a number from the menu. The do while loop will ensure that I get the choice in the right range. I now just need to be sure that the number entered is not a decimal. I thought that the while loop with in would solve this problem but it does not. I want to know if there is something that I can do to loop the scanf untill I get a positive whole number in the range 1 through 6.
Code:
do
{
printf ("Please enter a number from the menu.\n");
printf ("1. Inches to centimeters\n");
printf ("2. Feet to meters\n");
printf ("3. Miles to kilometers\n");
printf ("4. Pounds to kilograms\n");
printf ("5. Gallons to liters\n");
printf ("6. Quit the program\n");
printf ("What Would You Like To Do?:");
scanf ("%d", &menuChoice);
while (!scanf("%d", &menuChoice));
{
printf ("Enter a choice 1, 2, 3, 4, 5, or 6.\n");
scanf ("%d", &menuChoice);
}
}
while ((menuChoice < 1) || (menuChoice > 6));
Thanks
Justin