I want the user to input 2 values, and I'm unsure of what to use to make sure when the user enters a character rather than a numeric values, that it prompts the user to enter a numeric values.
CODE
int main()
{
int choice;
cout << "\nKU Standard to Metric System Conversion 1.0\n\n";
cout << "What would you like to convert?\n";
cout << " 1) Fahrenheit to Celsius\n";
cout << " 2) Miles to Kilometers\n";
cout << " 3) Pounds to Kilograms\n";
cout << " 4) Gallons to Liters\n";
cout << " 5) ~ End Program ~\n\n";
cout << "Menu Choice: ";
cin >> choice;
// It is at this point I want the input evaluated and made sure that it is between 0 - 5 and an integer.
while (choice > 5 || choice < 0)
{
cout << "\nChoose a menu choice from above.\n";
cout << "Menu Choice: ";
cin >> choice;
cout << "\n";
}
switch (choice)
{
case 1:
fahr2cels();
main();
break;
case 2:
mi2km();
break;
case 3:
lb2kg();
break;
case 4:
gal2lit();
break;
case 5:
break;
}
}
This is only part of my code; however, this is the code that matters. I tried doing, in my while statement, "choice != int(choice)," and similar things. I just want a basic way of fixing this if available or at least insight on how I could easily do it. Thanks!
EDIT: Also, as of right now, when you enter anything other than a number, it repeats what is in the while loop infinitely.
This post has been edited by jeisma: 27 Sep, 2006 - 12:26 PM