I have been having trouble entering an error check to this code for when a user inputs a letter instead of numbers for the Celsius or Fahrenheit input
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float Celsius = 0; //variable for Celsius
float Fahrenheit = 0; //variable for Fahrenheit
char Selection = 0; //variable for menu selection
char Again = 0; //variable to repeat menu
char Exit = 0; //confirm quit
cout << setprecision(2) << fixed << showpoint;
// setting precision for accurate display
cout << "This program will assist in converting degrees up to the" << endl;
cout << "hundredths decimal value" << endl;
// informing the user of what the program is used for and what format to use
cout << endl;
do
{
cout << "Please select one of the following options:" << endl;
cout << endl;
cout << setw(35) << "1. Convert Celsius to Fahrenheit" << endl;
cout << setw(35) << "2. Convert Fahrenheit to Celsius" << endl;
cout << setw(10) << "3. Quit" << endl; //menu selection
cout << endl;
cin >> Selection;
cout << endl;
switch( Selection ) // This is where the switch statement begins
{
case '1': // Calculates C to F
{
cout << "Please input the beginning degrees in Celsius" << endl;
cout << endl;
cin >> Celsius;
Fahrenheit = ( 9.00 / 5 ) * Celsius + 32 ;
cout << endl;
cout << "The calculate degrees to Fahrenheit is: " << Fahrenheit << endl;
cout << endl;
cout << "Would you like to start over? (Y/N)" << endl; //Restart option
cout << endl;
cin >> Again;
cout << endl;
}
break;
case '2': // Calculates F to C
{
cout << "Please input the beginning degrees in Fahrenheit" << endl;
cout << endl;
cin >> Fahrenheit;
Celsius = ( 5.00 / 9 ) * (Fahrenheit - 32) ;
cout << endl;
cout << "The calculate degrees to Celsius is: " << Celsius << endl;
cout << endl;
cout << "Would you like to start over? (Y/N)" << endl; //Restart option
cout << endl;
cin >> Again;
cout << endl;
}
break;
case '3': // Quit program
{
cout << "Would you like to start over? (Y/N)" << endl; //Restart option
cout << endl;
cin >> Again;
cout << endl;
}
break;
default:
{
cout << "You did not enter a valid option" << endl; // error check
cout << endl;
cout << "Would you like to start over? (Y/N)" << endl; //Restart option
cout << endl;
cin >> Again;
cout << endl;
}
}
}
while ( Again == 'Y' || Again == 'y' );
cout << "Thank you. Good bye" << endl; // end message
cout << endl;