Hello guys I have a problem with my code: I want to print an error message every time the user enters a number lower than -273.15 . My code runs well and does the desired mathematical operation. It even loops back to the input message, but I'm having huge headaches trying to sort out how to best approach that simple task of adding a cout statement to the validation loop. =(
#include <iostream>
using namespace std;
int main ()
{
double dCel, dFah;
// user inputs temp then it's converted to Fahrenheit
do {
cout << "Enter the temperature in Celsius: \t \n ";
cin >> dCel;
}
while (dCel < -273.15);
dFah = dCel * (9.0/5.0) + 32.0;
cout<< "\t" << dCel << " \tdegrees Celsius converts to: " << dFah << " degrees Fahrenheit \n "<<endl ;
// user inputs temp in Fah and converted to Cel
do {
cout << "Enter the temperature in Fahrenheit: \t \n";
cin >> dFah;
}
while ( dFah < -273.15 );
dCel = (dFah - 32.0) * (5.0/9.0);
cout << " \t " << dFah << "\t degrees Fahrenheit converts to: " << dCel << " degrees Celsius \n ";
//system pause only used to copy console output window
system ("pause");
return 0;
}
desired output:
**This part works ok ;
/*
Enter the temperature in Celsius:
100
100 degrees Celsius converts to: 212 degrees Fahrenheit
Enter the temperature in Fahrenheit:
100
100 degrees Fahrenheit converts to: 37.7778 degrees Celsius
Press any key to continue . . .
*/
But, this part not so:
/*
Enter the temperature in Celsius:
-300
Enter the temperature in Celsius:
-500
Enter the temperature in Celsius: */
As you can see it basically does what I want on the math side, but I have no idea how to insert an error message to the do while loop.
Thanks in advance,
Jean