I've got a pretty simple program that calculates the area of a triangle. It works fine and returns my error message if the user inputs 0 or a negative number (triBase and triHeight are defined as float earlier in the code), but how do I handle it if the user inputs "four" or "4 feet"?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{
cout << "What is the base of the triangle? "; //Collect required information.
cin >> triBase;
cout << "What is the height of the triangle? ";
cin >> triHeight;
if (triBase*triHeight>0) //Checks for invalid data.
{
cout << "The area of your rectangle is " << triBase*triHeight << ".\n"; // Calculate and display the area.
}
//Returns error message and kills program if one or more inputs is invalid.
else
cout << "One or more inputs are invalid. Please run the program again.\n";
}