-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_Celsius.cc
31 lines (27 loc) · 895 Bytes
/
to_Celsius.cc
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
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
float toFahrenheit(float Celsius) { return (Celsius * (9.0 / 5.0) + 32.0); }
float toCelsius(float Fahrenheit) {
return ((Fahrenheit - 32.0) * (5.0 / 9.0));
}
int main(int argc, char **argv) {
if (argc != 2) {
cout << "Invoke with one numeric parameter." << endl;
exit(EXIT_FAILURE);
}
string input(argv[1]);
float temperature = strtof(argv[1], nullptr);
if ((input.find("F") != string::npos)) {
cout << "Fahrenheit: " << ceil(temperature)
<< "; Celsius: " << ceil(toCelsius(temperature)) << "C" << endl;
} else if ((input.find("C") != string::npos)) {
cout << "Celsius: " << ceil(temperature)
<< "; Fahrenheit: " << ceil(toFahrenheit(temperature)) << "F" << endl;
} else {
cout << "Illegal input." << endl;
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}