diff options
| author | prestonderek <[email protected]> | 2022-11-06 14:33:35 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-06 14:33:35 -0800 |
| commit | d7a4fd11d53c7be7646b538f57ff31bf1f3b9501 (patch) | |
| tree | 59971159e0c7d9b3e9e400d3b445a2720dc1e7ea /CST116-Lab2-Preston.cpp | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab2-prestonderek-d7a4fd11d53c7be7646b538f57ff31bf1f3b9501.tar.xz cst116-lab2-prestonderek-d7a4fd11d53c7be7646b538f57ff31bf1f3b9501.zip | |
Add files via upload
VS and GitHub are having trouble communicating. This is the best I can do for a commit right now
Diffstat (limited to 'CST116-Lab2-Preston.cpp')
| -rw-r--r-- | CST116-Lab2-Preston.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/CST116-Lab2-Preston.cpp b/CST116-Lab2-Preston.cpp new file mode 100644 index 0000000..4d15f4e --- /dev/null +++ b/CST116-Lab2-Preston.cpp @@ -0,0 +1,122 @@ +// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include <iostream> +#include <iomanip> +#include <string> +#include <cmath> + +using namespace std; + +using std::cout; +using std::cin; +using std::endl; + +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 + +{ + 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; +} + + + |