From 0dfa57992c535f26613c96460e550144c01632ad Mon Sep 17 00:00:00 2001 From: tafaar Date: Tue, 8 Nov 2022 17:46:55 -0800 Subject: added check wind function --- BlankConsoleLab/BlankConsoleLab.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'BlankConsoleLab/BlankConsoleLab.cpp') diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index e4b294e..a008590 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -37,10 +37,22 @@ float ConvertTemperature(float temperature, char initialSystem) { } +bool CheckWindSpeed(float& input) { + + if (input < 0 || input > 231) { + + cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl; + return false; + + } + else return true; + +} + int main() { cout << "Please enter a temperature between -80 to 121 degrees fahrenheit, or -62 and 49.5 degrees celsius." << endl; - cout << "Example entries: -32.3 F, 27.8 C" << endl; + cout << "Example entries: -32.3 F, 27.8 C\n" << endl; float tempInput; char tempSystem; @@ -95,13 +107,7 @@ int main() cin >> windSpeed; - if (windSpeed < 0 || windSpeed > 231) { - - cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl; - } - else { - validEntries = true; - } + validEntries = CheckWindSpeed(windSpeed); } while (validEntries == false); @@ -111,9 +117,9 @@ int main() cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl; - cout << setprecision(2) << fixed << left; - cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << endl; - cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windChill << endl; + cout << setprecision(1) << fixed << left; + cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << setw(colWidth) << "Wind Chill (C)" << endl; + cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windChill << setw(colWidth) << ConvertTemperature(windChill, 'F') << endl; return 0; -- cgit v1.2.3