diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..c7b68f7 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,6 +2,9 @@ // #include <iostream> +#include <iomanip> +#include <string> +#include <cmath> using namespace std; @@ -9,8 +12,110 @@ using std::cout; using std::cin; using std::endl; -int main() +float far; +float cel; +float mph; +float newFar; +float chill; + +const int celmin = -62; +const float celmax = 49.5; +const int farmin = -80; +const int farmax = 121; +const int mphmin = 0; +const int mphmax = 231; + +string check; +const string celcheck = "c"; + +float celtofar(float cel); +float getParam(float& far, float& mph); +float windchill(float far, float mph); +float getMPH(float& mph); + +int main() // calls functions and then displays the fahrenheit and windchill at the end + { - cout << "Hello World!\n"; + far = 0.0; + cel = 0.0; + mph = 0.0; + + cout << "Do you want to enter fahrenheit or celcius? Enter f or c" << endl; + cin >> check; + + if (check == celcheck) + { + celtofar(cel); + far = newFar; + getMPH(mph); + } + else + getParam(far, mph); + + windchill(far, mph); + + cout << "You entered " << far << "F" << endl; + cout << "For " << far << " degrees F and " << mph << " MPH wind speed, the windchill is: " << chill; + + return 0; } +float getParam(float& far, float& mph) //gets fahrenheit and wind speed from user +{ + cout << "Please enter your fahrenheit temp:" << endl; + cout << "Must be between " << farmin << " and " << farmax << endl; + cin >> far; + while (far < farmin || far > farmax) + { + cout << "Please enter your fahrenheit temp:" << endl; + cout << "Must be between " << farmin << " and " << farmax << endl; + cin >> far; + } + cout << "Please enter your wind speed in mph:" << endl; + cout << "Must be between " << mphmin << " and " << mphmax << endl; + cin >> mph; + while (mph < mphmin || mph > mphmax) + { + cout << "Please enter your wind speed in mph:" << endl; + cout << "Must be between " << mphmin << " and " << mphmax << endl; + cin >> mph; + } + return far, mph; +} + +float celtofar(float cel) //calculates celcius to fahrenheit and returns the value +{ + cout << "Please enter your celcius temp:" << endl; + cout << "Must be between " << celmin << " and " << celmax << endl; + cin >> cel; + while (cel < celmin || cel > celmax) + { + cout << "Please enter your celcius temp:" << endl; + cout << "Must be between " << celmin << " and " << celmax << endl; + cin >> cel; + } + newFar = (9 / 5) * cel + 32; + return newFar; +} + +float windchill(float far, float mph) //calculates wind chill and returns it +{ + chill = 35.74 + (.6215 * far) - (35.75 * pow(mph, .16)) + (.4275 * pow(far, .16)); + return chill; +} + +float getMPH(float& mph) //gets mph only for when you select celcius function +{ + cout << "Please enter your wind speed in mph:" << endl; + cout << "Must be between " << mphmin << " and " << mphmax << endl; + cin >> mph; + while (mph < mphmin || mph > mphmax) + { + cout << "Please enter your wind speed in mph:" << endl; + cout << "Must be between " << mphmin << " and " << mphmax << endl; + cin >> mph; + } + return mph; +} + + |