From 440863931dff8864f9cca1e62ff22f24dfd9088f Mon Sep 17 00:00:00 2001 From: Wyatt Date: Tue, 8 Nov 2022 21:03:04 -0800 Subject: lab done --- BlankConsoleLab/BlankConsoleLab.cpp | 100 ++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 4 deletions(-) (limited to 'BlankConsoleLab/BlankConsoleLab.cpp') diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..eb11344 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -5,12 +5,104 @@ using namespace std; -using std::cout; -using std::cin; -using std::endl; +const float MINFTEMP = -80; +const float MAXFTEMP = 121; + +const float MINCTEMP = -62; +const float MAXCTEMP = 49.5; + +const float MINWSPEED = 0; +const float MAXWSPEED = 231; + + +const string YES_WORD = "yes"; + +void convertValueToFarenheit(float& celsiusvalue); +float calculateWindChill(float temp, float wind_speed); +void outputData(float temp, float wind_speed, float wind_chill); int main() { - cout << "Hello World!\n"; + float temp = -81; + float wind_speed = -1; + + + bool ferenheit = true; + string input_word; + + cout << "Will you be inputting your data in celcius? If yes, then please type 'yes': "; + cin >> input_word; + cout << endl; + cin.clear(); + if (input_word == YES_WORD) + { + ferenheit = false; + } + + while ( + (ferenheit && ((MINFTEMP > temp) || (MAXFTEMP < temp))) || + (!ferenheit && ((MINCTEMP > temp) || (MAXCTEMP < temp))) + ) + { + if (ferenheit) + { + cout << "Please input a temperature in Ferenheit, it must not be less than " << MINFTEMP << "F or greater than " << MAXFTEMP << "F.: "; + } + else { + cout << "Please input a temperature in Celcius, it must not be less than " << MINCTEMP << "C or greater than " << MAXCTEMP << "C.: "; + } + + cin >> temp; + cout << endl; + cin.clear(); + } + + if (!ferenheit) convertValueToFarenheit(temp); + + + while ((MINWSPEED > wind_speed) || MAXWSPEED < wind_speed) + { + cout << "Please input a wind speed in Miles per Hour, it must not be less than " << MINWSPEED << "m/p or greater than " << MAXWSPEED << "m/p.: "; + cin >> wind_speed; + cout << endl; + cin.clear(); + } + + + outputData(temp, wind_speed, calculateWindChill(temp, wind_speed)); + + return 0; +} + +/// +/// Edits the reference 'celsiusvalus' to conver it to Ferenheit; +/// +/// +void convertValueToFarenheit(float& celsiusvalue) +{ + celsiusvalue * (9.0 / 5.0); + celsiusvalue += 32; +} +/// +/// Calculates the wind chill and returns that from temp and wind_speed; +/// +/// +/// +/// +float calculateWindChill(float temp, float wind_speed) +{ + return 35.74 + .6215 * temp - 35.75 * powf(wind_speed, 0.16) + .4275 * temp * powf(wind_speed, 0.16); +} +/// +/// Outputs the three inputs to the console with formatting; +/// +/// +/// +/// +void outputData(float temp, float wind_speed, float wind_chill) +{ + cout << "Temperature: " << temp << "F" << + "\n Wind Speed: " << wind_speed << "m/p" << + "\n Wind chill: " << wind_chill << endl; } -- cgit v1.2.3