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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * 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>
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:"<<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";
        }
        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.