diff options
Diffstat (limited to 'Project/program.cpp')
| -rw-r--r-- | Project/program.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Project/program.cpp b/Project/program.cpp new file mode 100644 index 0000000..9e2cb82 --- /dev/null +++ b/Project/program.cpp @@ -0,0 +1,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; +}
\ No newline at end of file |