From f4255c5923d4d514b01d987b26902ee2c2c52de6 Mon Sep 17 00:00:00 2001 From: jacobdw22 Date: Wed, 2 Nov 2022 12:59:19 -0700 Subject: Added a windspeed calculator, not yet in a function. --- BlankConsoleLab/cst116-lab2-wilson.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'BlankConsoleLab/cst116-lab2-wilson.cpp') diff --git a/BlankConsoleLab/cst116-lab2-wilson.cpp b/BlankConsoleLab/cst116-lab2-wilson.cpp index f6e2ee4..03f0859 100644 --- a/BlankConsoleLab/cst116-lab2-wilson.cpp +++ b/BlankConsoleLab/cst116-lab2-wilson.cpp @@ -21,7 +21,7 @@ const float CMAX = 49.5; const float CMIN = -62; //Set values for minimum and maximum temperatures. -float CtoF(float Fahrenheit, float Celsius) { +float CtoF(float Fahrenheit, float Celsius) { //float function so that it returns a float Fahrenheit = (Celsius * 9.0 / 5.0) + 32.0; //Converts Celsius to Fahrenheit @@ -36,6 +36,7 @@ int main() { float Celsius = 0.0; //Defines Celsius for the conversion function float Fahrenheit = 0.0; //Defines Fahrenheit for the conversion function + float windspeed = 0.0; Loop: //Placeholder to loop back to @@ -43,11 +44,26 @@ int main() cin >> Celsius; //Reads in Celsius from the user input if (Celsius <= CMAX && Celsius >= CMIN) { - cout << Celsius << " Degrees Celsius is approximately " << CtoF(Fahrenheit, Celsius) << " Degrees Fahrenheit\n\n"; + cout << "\t" << Celsius << " Degrees Celsius is approximately " << CtoF(Fahrenheit, Celsius) << " Degrees Fahrenheit\n\n"; } else { goto Loop; //Goes back to placeholder to Loop in case of invalid response (past limits) } + + Loop2: + + cout << "Please enter the wind speed between 0 and 231 mph: "; + cin >> windspeed; + + if (windspeed <= 231.0 && windspeed >= 0.0) { + cout << "\n\tThe temperature is " << CtoF(Fahrenheit, Celsius) << " degrees Fahrenheit and the windspeed is " << windspeed << " mph." << endl; + } + else { + goto Loop2; //Goes back to placeholder to Loop in case of invalid response (past limits) + } + + + } -- cgit v1.2.3