diff options
| author | tafaar <[email protected]> | 2022-11-08 17:46:55 -0800 |
|---|---|---|
| committer | tafaar <[email protected]> | 2022-11-08 17:46:55 -0800 |
| commit | 0dfa57992c535f26613c96460e550144c01632ad (patch) | |
| tree | 12f5809186fae2834b46aeeee480fb0c6283ee6b /BlankConsoleLab | |
| parent | wrote most of the program (diff) | |
| download | cst116-lab2-hill-0dfa57992c535f26613c96460e550144c01632ad.tar.xz cst116-lab2-hill-0dfa57992c535f26613c96460e550144c01632ad.zip | |
added check wind function
Diffstat (limited to 'BlankConsoleLab')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
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; |