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 4c8307914942450eacbe407c21a8e4306653ad0f..2ed77901dca72581a2033fdd22972a28d79ecb11 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; +}