From ca8487143e3d670f2ecfced614119582c73b150b Mon Sep 17 00:00:00 2001 From: Rudi Buss <rudi.buss@th-deg.de> Date: Thu, 29 Aug 2024 21:41:00 +0200 Subject: [PATCH] Update Solution Exercise 2 - Fahrenheit into celsius.cpp --- ...n Exercise 2 - Fahrenheit into celsius.cpp | 93 ++++++++----------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/Part 1/4. Control structures/Solutions/Solution Exercise 2 - Fahrenheit into celsius.cpp b/Part 1/4. Control structures/Solutions/Solution Exercise 2 - Fahrenheit into celsius.cpp index 4c83079..2ed7790 100644 --- a/Part 1/4. Control structures/Solutions/Solution Exercise 2 - Fahrenheit into celsius.cpp +++ b/Part 1/4. Control structures/Solutions/Solution Exercise 2 - Fahrenheit into celsius.cpp @@ -2,56 +2,45 @@ using namespace std; -int main() -{ - float fahrenheit; - float tmp; - float celsius; - int stepsize = 20; - int maximum = 300; - - do - { - cout << "Fahrenheit: "; - cin >> fahrenheit; - }while(fahrenheit<=0); - - tmp = fahrenheit; - cout << "Step size: "; - cin >> stepsize; - cout << "Maximum: "; - cin >> maximum; - - cout << endl; - - for(fahrenheit=tmp; fahrenheit <= maximum; fahrenheit+=stepsize) - { - celsius = ((fahrenheit - 32) * 5) / 9; - cout << "Fahrenheit: " << fahrenheit << "\t| Celsius: " << celsius << endl; - } - - cout << endl; - fahrenheit = tmp; - - while(fahrenheit <= maximum) - { - celsius = (((fahrenheit - 32) * 5) / 9); - if( celsius <= 10) - { - cout << "It is " << celsius << " \tdegrees and it is cold" << endl; - } - else if(celsius <= 20) - { - cout << "It is " << celsius << " \tdegrees and it is pleasantly warm" << endl; - } - else - { - cout << "It is " << celsius << " \tdegrees and it is getting hot" << endl; - } - fahrenheit += stepsize; - } - - - return 0; -} +int main() { + float fahrenheit; + float tmp; + float celsius; + int stepsize = 20; + int maximum = 300; + + do { + cout << "Fahrenheit: "; + cin >> fahrenheit; + } while (fahrenheit <= 0); + + tmp = fahrenheit; + cout << "Step size: "; + cin >> stepsize; + cout << "Maximum: "; + cin >> maximum; + + cout << endl; + for (fahrenheit = tmp; fahrenheit <= maximum; fahrenheit += stepsize) { + celsius = ((fahrenheit - 32) * 5) / 9; + cout << "Fahrenheit: " << fahrenheit << "\t| Celsius: " << celsius << endl; + } + + cout << endl; + fahrenheit = tmp; + + while (fahrenheit <= maximum) { + celsius = (((fahrenheit - 32) * 5) / 9); + if (celsius <= 10) { + cout << "It is " << celsius << " \tdegrees and it is cold" << endl; + } else if (celsius <= 20) { + cout << "It is " << celsius << " \tdegrees and it is pleasantly warm" << endl; + } else { + cout << "It is " << celsius << " \tdegrees and it is getting hot" << endl; + } + fahrenheit += stepsize; + } + + return 0; +} -- GitLab