### fahren to cel

i donno what was wrong with my answer.
I cant get great marks... only got 8/10 marks..

Pls correct me if iam wrong.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````/** * 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 using namespace 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:"<> 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"; } else if(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; }``````

thanks
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
Topic archived. No new replies allowed.