From d44a3713cf34ec5ef9e39a921cc26e50b4915e86 Mon Sep 17 00:00:00 2001 From: ludwig Date: Thu, 18 Aug 2022 21:01:16 -0500 Subject: [PATCH] While loop to shorten things up --- converter.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/converter.cpp b/converter.cpp index 365eb65..22ef8c6 100644 --- a/converter.cpp +++ b/converter.cpp @@ -28,24 +28,23 @@ int main() { Menu(); cin >> input; - if (input == 3) { - cout << "Quitting..." << endl; + while (input != 3) { + + if (input == 1) { + cout << "Enter temperature in Celsius: "; + cin >> input; + C = input; + cout << convertF(C, F) << endl; + break; + } else if (input == 2) { + cout << "Enter temperature in Fahrenheit: "; + cin >> input; + F = input; + cout << convertC(C, F); + break; + } } - - else if (input == 1){ - cout << "Enter temperature in Celsius: "; - cin >> input; - C = input; - cout << convertF( C, F) << endl; - } - - else if (input == 2){ - cout << "Enter temperature in Fahrenheit: "; - cin >> input; - F = input; - cout << convertC(C, F); - } - + cout << "\nExiting..."; return(0); }