1: //ftemp_to_ctemp1.cpp
2: //Converts a Fahrenheit temperature to Celsius.
4: #include <iostream>
5: using namespace std;
8: int CelsiusTemp(double fTemp)
9: {
10: const double C_DEGREE_PER_F_DEGREE = double(5) / double(9);
12: double cTemp = (fTemp - 32) * C_DEGREE_PER_F_DEGREE;
14: if (cTemp >= 0)
15: return int(cTemp + 0.5);
16: else
17: return int(cTemp - 0.5);
18: }
21: int main()
22: {
23: cout << "\nThis program converts a Fahrenheit temperature to "
24: "an equivalent Celsius value.\nBoth values are reported in "
25: "rounded form.\n\n";
27: double fTemp;
28: cout << "Enter your Fahrenheit value here: ";
29: cin >> fTemp; cin.ignore(80, '\n');
31: //Round the Fahrenheit temperature to the nearest integer
32: if (fTemp >= 0)
33: fTemp = int(fTemp + 0.5);
34: else
35: fTemp = int(fTemp - 0.5);
37: cout << "\nFahrenheit Temperature: " << fTemp
38: << "\nEquivalent Celsius Value: " << CelsiusTemp(fTemp);
39: cout << endl << endl;
40: }