From 46abf6856a417cdc564b0bc11c16f9287c8268ab Mon Sep 17 00:00:00 2001 From: Yana Blashchishina Date: Sat, 27 Jan 2024 19:52:56 -0800 Subject: homework 2 completed --- Homework2/Homework2/source.cpp | 77 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'Homework2') diff --git a/Homework2/Homework2/source.cpp b/Homework2/Homework2/source.cpp index 12ef271..33b68ee 100644 --- a/Homework2/Homework2/source.cpp +++ b/Homework2/Homework2/source.cpp @@ -1,4 +1,79 @@ // Name: Yana Blashchishina // Date: 01/27/2024 // Class: CST116 -// Assignment: Homework 2 \ No newline at end of file +// Assignment: Homework 2 + +#include + +using std::cout; +using std::cin; +using std::endl; + + + +double CelsiusToFahrenheit(double celsius) { +#ifdef VERBOSE + cout << "Converting" << celsius << "C to Fahrenheit" << endl; + + cout << "F=32+(9/5*" << celsius << "C") << endl; +#endif + return 32 + (9.0 / 5) * celsius; +} + +double FahrenheitToCelsius(double fahrenheit) { +#ifdef VERBOSE + cout << "Converting" << fahrenheit < , "F to Celsius" << endl; + cout << "C=(5/9) * (" << fahrenheit << "F-32)" << endl; + +#endif + return (5.0 / 9) * (fahrenheit - 32); + + +} + +int main() +{ + char option; + double temperature; + + cout << "Choose an option" << endl; + + cout << "(a) Celsius to Fahrenheit" << endl; + + cout << "(b) Fahrenheit to Celsius" << endl; + + cin >> option; + + + cout << "Enter temperature to convert"; + cin >> temperature; + + + switch (option) { + case 'a': + cout << temperature << " Celsius is " << CelsiusToFahrenheit(temperature) << " Fahrenheit." << endl; + + if (temperature >= 100) + cout << "Ouch! That's too hot!" << endl; + else if (temperature <= 100) + cout << "You'll freeze!" << endl; + break; + + + case'b': + cout << temperature << " Fahrenheit is" << FahrenheitToCelsius(temperature) << " Celsius." << endl; + + if (temperature >= 212) + cout << "Ouch! That's too hot!" << endl; + else if (temperature <= 32) + cout << "You'll freeze!" << endl; + break; + + default: + cout << "Inavlid option" << endl; + return 1; + + } + + return 0; +} \ No newline at end of file -- cgit v1.2.3