blob: 9e2cb820796df25a112dba5400898dda5311376e (
plain) (
blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include <iostream>
using namespace std;
#define VERBOSE
void celsiusToFahrenheit(double celsius) {
double fahrenheit = 32 + (9.0 / 5.0 * celsius);
cout << "temperature in fahrenheit: " << fahrenheit << endl;
#ifdef VERBOSE
cout << "F = 32 + (9/5 * " << celsius << ")" << endl;
cout << "F = " << fahrenheit << endl;
#endif
if (celsius >= 100)
cout << "temp is: boiling temp\n";
else if (celsius >= 40)
cout << "temp is: very hot\n";
else if (celsius >= 20)
cout << "temp is: warm\n";
else if (celsius >= 10)
cout << "temp is: cold\n";
else if (celsius >= 0)
cout << "temp is: almost freezing\n";
else
cout << "temp is: freezing\n";
}
void fahrenheitToCelsius(double fahrenheit) {
double celsius = (fahrenheit - 32) * 5.0 / 9.0;
cout << "temperature in celsius: " << celsius << endl;
#ifdef VERBOSE
cout << "C = (F - 32) * 5/9" << endl;
cout << "C = " << celsius << endl;
#endif
if (celsius >= 100)
cout << "temp is: boiling temp\n";
else if (celsius >= 40)
cout << "temp is: very hot\n";
else if (celsius >= 20)
cout << "temp is: warm\n";
else if (celsius >= 10)
cout << "temp is: cold\n";
else if (celsius >= 0)
cout << "temp is: almost freezing\n";
else
cout << "temp is: freezing\n";
}
int main() {
char option;
double temperature;
cout << "select an option:\n";
cout << "1: celsius to fahrenheit\n";
cout << "2: fahrenheit to celsius\n";
cin >> option;
if (option == '1') {
cout << "enter temperature in celsius: ";
cin >> temperature;
celsiusToFahrenheit(temperature);
}
else if (option == '2') {
cout << "enter temperature in fahrenheit: ";
cin >> temperature;
fahrenheitToCelsius(temperature);
}
else {
cout << "invalid input\n";
}
return 0;
}
|