diff options
| author | Musa Ahmed <[email protected]> | 2022-11-06 17:08:05 -0800 |
|---|---|---|
| committer | Musa Ahmed <[email protected]> | 2022-11-06 17:08:05 -0800 |
| commit | 01d0935d687dc4b20a167d28294762ce5e0a6a6a (patch) | |
| tree | 98acc88abf38baaabcc67d2873539f94c584ee5d | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab2-m005a-01d0935d687dc4b20a167d28294762ce5e0a6a6a.tar.xz cst116-lab2-m005a-01d0935d687dc4b20a167d28294762ce5e0a6a6a.zip | |
finished msot of the calcualtions
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 100 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj | 8 |
2 files changed, 103 insertions, 5 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..b343e4b 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,6 +2,8 @@ // #include <iostream> +#include <string> +#include <iomanip> // std::setprecision using namespace std; @@ -9,8 +11,104 @@ using std::cout; using std::cin; using std::endl; +float cToF(float a) { + float temp = (9.0 / 5) * a + 32; + return temp; +} + +float windChill(float& d, float& w) { + float out = 35.74 + 0.6215 * d - 35.75 * pow(w, 0.16) + 0.4275 * d * pow(w, 0.16); + return out; +} +string output(float d, float w, float chill, bool x) { + string temp; + + if (x == true) { + temp = "fahrenheit"; + } + else { + temp = "celsius"; + } + return "For " + to_string(d) + " " + temp + " and " + to_string(w) + " mph wind, the windchill is: " + to_string(chill); +} int main() { - cout << "Hello World!\n"; + const int MINF = -80; + const int MAXF = 121; + const int MINC = -62; + const float MAXC = 49.5; + float c = 0; + float f = 0; + float w; + string temp; + bool range = false; + bool tilSpeed = false; + bool isF = false; + cout << "Do you want to enter in Fahrenheit (F) or (C)" << endl; + cin >> temp; + while(range == false) { + + if (temp == "C") { + range = true; + cout << "Enter a temperature in Celsius between -62 and 49.5: " << endl; + cin >> c; + if (c < MINC || c > MAXC) { + range = false; + } + else { + cout << "You entered " << c << " degrees celsius, or " << cToF(c) << " degrees fahrenheit" << endl; + + tilSpeed = true; + } + + + } + else if (temp == "F") { + range = true; + cout << "Enter a temperature in Fahrenheit between -80 and 121: " << endl; + cin >> f; + if (f < MINF || f > MAXF) { + range = false; + } + else { + cout << "You entered " << f << " degrees fahrenheit" << endl; + tilSpeed = true; + } + + + + } + + else { + cout << "Do you want to enter in Fahrenheit (F) or (C)" << endl; + cin >> temp; + } + + if (range == true) { + tilSpeed = true; + cout << "Enter a speed between 0 and 231: " << endl; + cin >> w; + while (w > 231 || w < 0) { + cout << "Enter a speed between 0 and 231: " << endl; + cin >> w; + + } + } + + } + + if (c != 0) { + isF = false; + cout << setprecision(2) << output(c, w, windChill(c, w), isF); + + } + + else if (f != 0) { + isF = true; + cout << setprecision(2) << output(f, w, windChill(f, w), isF); + + } + + } diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db2e734..d2e3ee2 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -29,26 +29,26 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> |