forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemperatureConvertion.cpp
90 lines (74 loc) · 2.47 KB
/
TemperatureConvertion.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
int main(){
cout << "=========================" << endl;
cout << "= CONVERTER PROGRAM =" << endl;
cout << "= HACKTOBERFEST =" << endl;
cout << "= 2022 =" << endl;
cout << "=========================" << endl;
cout << "Temperature code : (C) Celcius, (R) Reaumur, (F) Fahrenheit, (K) Kelvin" << endl;
cout << "# NOTE # Make sure you input an upper case character # NOTE #" << endl;
char tempcode1, tempcode2;
cout << "Input temperature code 1 : ";
cin >> tempcode1;
if(!(tempcode1 == 'C' or tempcode1 == 'R' or tempcode1 == 'F' or tempcode1 == 'K')){
cout << "Invalid temperature code 1";
return 0;
}
cout << "Input temperature code 2 : ";
cin >> tempcode2;
if(!(tempcode2 == 'C' or tempcode2 == 'R' or tempcode2 == 'F' or tempcode2 == 'K')){
cout << "Invalid temperature code 2";
return 0;
}
double temp, ans;
cout << "Input temperature : ";
cin >> temp;
if(tempcode1 == 'C'){
if(tempcode2 == 'C'){
cout << "Imagine converting Celcius to Celcius" << endl;
} else if(tempcode2 == 'R'){
ans = 4.0 / 5.0 * temp;
} else if(tempcode2 == 'F'){
ans = 9.0 / 5.0 * temp + 32;
} else if(tempcode2 == 'K'){
ans = 273.15 + temp;
}
} else if(tempcode1 == 'R'){
if(tempcode2 == 'C'){
ans = 5.0 / 4.0 * temp;
} else if(tempcode2 == 'R'){
cout << "Imagine converting Reaumur to Reaumur" << endl;
} else if(tempcode2 == 'F'){
ans = 9.0 / 4.0 * temp + 32;
} else if(tempcode2 == 'K'){
ans = 5.0 / 4.0 * temp + 273.15;
}
} else if(tempcode1 == 'F'){
if(tempcode2 == 'C'){
ans = (5.0 / 9.0) * (temp - 32);
} else if(tempcode2 == 'R'){
ans = (4.0 / 9.0) * (temp - 32);
} else if(tempcode2 == 'F'){
cout << "Imagine converting Fahrenheit to Fahrenheit" << endl;
} else if(tempcode2 == 'K'){
ans = (5.0 / 9.0) * (temp - 32) + 273.15;
}
} else if(tempcode1 == 'K'){
if(tempcode2 == 'C'){
ans = temp - 273.15;
} else if(tempcode2 == 'R'){
ans = (4.0 / 5.0) * (temp - 273.15);
} else if(tempcode2 == 'F'){
ans = (9.0 / 5.0) * (temp - 273.15) + 32;
} else if(tempcode2 == 'K'){
cout << "Imagine converting Kelvin to Kelvin" << endl;
}
}
cout << "The temperature answer is ";
cout << ans;
/*
Credit :
Coded by Ibnu Dzumirrotin (https://github.com/Ibnudz)
*/
}