/**
* prints out the results of
* degree celcius after converting from fahrenheit.
*
* There is 3 condition to print out
* By using fahrenheitToCelsius and printTemperatureMessage function name.
* 1: Less than 20 deg Cels, - It is so cold
* 2: Between 20 deg Cels and 40 degree Celsius inclusive - Standard temperature
* 3: Greater than 40 deg Cels - So so so hot
*
*/
#include <iostream>
usingnamespace std;
int main()
{
int farh; // fahrenheight
int check; // check the degree input
int fahrenheitToCelsius = 0; // convert fahrenheith to celcius
string printTemperatureMessage; // print the answer
/** Process */
do {
cout << "Please insert fahrenheit more than 32 degree Fahrenheit or less than 140 degree Fahrenheit:"<<endl;
cin >> farh;
if ((farh < 32) || (farh > 140)){
check = 1;
}
else {check=0;}
}while (check !=0);
/** fahrenheitToCelsius
/** printTemperatureMessage
/** (celsius + 32) * 5 / 9 */
fahrenheitToCelsius = (farh + 32) * 5 / 9; // convert Fahrenheight to celcius
if(fahrenheitToCelsius > 40){
printTemperatureMessage = "Ahhh! So so so hot";
}
elseif(fahrenheitToCelsius > 20 || fahrenheitToCelsius <= 40){
printTemperatureMessage = "Hmmm! Standard Malaysia temperature";
}
else {
printTemperatureMessage = "Wow! It is so cold";
}
/** Print Out The Answer */
cout << printTemperatureMessage << endl; //
return 0;
}
Two small errors:
1. Conversion to Celsius has the wrong sign
fahrenheitToCelsius = (farh - 32) * 5 / 9;
2. You will never get to the third condition (the too cold) because your second condition is Celsius greater than 20 OR Celsius less then 40. You should use the AND operator (in C++ is "&&"). In your case you don't even need that, since you take care of the case Celsius greater than 40 before, which means that if you arrive at that checkpoint fahrenheitToCelsius <= 40 is always a true statement