Hello, I recently started a c++ class, and one of the assignments is that we need to create a c++ program which converts Fahrenheit to Celsius. I have succeeded into doing just that, but I need to validate user input's values, meaning that the program must reject any entries that contains letters, and when it finally accepts the entry, it still does the calculations(the function is executed). Does anyone know how to do this? Any help is appreciated:
#include <iostream>
#include <iomanip>
using namespace std;
float FahrenheitToCelsius(float);
int main()
{
float fahrenheit;
int choice;
char input[10];
do{
cout << "This program converts fahrenheit to celsius" << endl << endl ;
cout << "Please Enter Fahrenheit Degrees: ";
cin >> fahrenheit;
while (fahrenheit = !isdigit){
cin.clear();
fflush(stdin);
cout <<"error";
cin >> fahrenheit;
}
cout << "Your Conversion Is: "<< fahrenheit << " Degree Fahrenheit to:" << endl;
cout << FahrenheitToCelsius(fahrenheit)<< fixed << setprecision(2) <<" Degrees Celsius.";
cout << "Want To Play Again?";
cout << "1 == Yes";
cout << "2 == No " << endl;
cin >> choice;
} while (choice == 1);
cin.get();
return 0;
}
float FahrenheitToCelsius(float fahrenheit)
{
return fahrenheit = (5.0/9.0) * (fahrenheit - 32);
}