summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCEOofOogaBooga <[email protected]>2022-11-08 20:53:23 -0800
committerCEOofOogaBooga <[email protected]>2022-11-08 20:53:23 -0800
commit038edda00013f202235479f5ef337010f1d94f80 (patch)
tree9c13b3bb7ed757584b894c29b31d05f0aacfa3d6
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab2--trinh--038edda00013f202235479f5ef337010f1d94f80.tar.xz
cst116-lab2--trinh--038edda00013f202235479f5ef337010f1d94f80.zip
Finished 1.0
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp95
1 files changed, 88 insertions, 7 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..2f31385 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -1,16 +1,97 @@
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
+/*
+Thomas Trinh
+CST116
+Lab2: Calculate the wind chill given a temperature and wind speed
+*/
#include <iostream>
-
+#include <iomanip>
using namespace std;
-using std::cout;
-using std::cin;
-using std::endl;
+const float MinF = -80;
+const float MaxF = 121;
+const float MinC = -62;
+const float MaxC = 49.5;
+const float MinW = 0;
+const float MaxW = 231;
+const string word = "yes";
+void converCelsiustoFahrenheit(float& celciusvalue);
+float WindChillcalc(float temp, float wspeed);
+void outputdata(float temp, float wspeed, float wchill);
int main()
{
- cout << "Hello World!\n";
-}
+ float temp = 122;
+ float wspeed = 232;
+
+ bool fahrenheit = true;
+ string input;
+
+ cout << "Are you entering temperature in celsius? Say yes if yes, no or anything else if no: ";
+ cin >> input;
+ cout << endl;
+
+ if (input == word)
+ {
+ fahrenheit = false;
+ }
+
+ while (fahrenheit && ((MinF > temp) || (MaxF < temp)) || (!fahrenheit && ((MinC > temp) || (MaxC < temp))))
+ {
+ if (fahrenheit)
+ {
+ cout << "Input a fahrenheit temperature that is greater than " << MinF << " but less than " << MaxF << ": ";
+ }
+ else {
+ cout << "Input a celsius temperature that is greater than " << MinC << " but less than " << MaxC << ": ";
+ }
+
+ cin >> temp;
+ cout << endl;
+
+ }
+ if (!fahrenheit) converCelsiustoFahrenheit(temp);
+ while ((MinW > wspeed) || (MaxW < wspeed))
+ {
+ cout << "Input a wind speed in mph that is greater than " << MinW << " but less than " << MaxW << ": ";
+ cin >> wspeed;
+ cout << endl;
+ }
+
+ outputdata(temp, wspeed, WindChillcalc(temp, wspeed));
+
+ return 0;
+}
+/// <summary>
+/// Changes the reference celciusvalue to fahrenheit
+/// </summary>
+/// <param name="celciusvalue"></param>
+void converCelsiustoFahrenheit(float& celciusvalue)
+{
+ celciusvalue * (9.0 / 5.0);
+ celciusvalue + 32;
+}
+/// <summary>
+/// Calculates the wind chill and returns it from the temperature and wind speed
+/// </summary>
+/// <param name="temp"></param>
+/// <param name="wspeed"></param>
+/// <returns></returns>
+float WindChillcalc(float temp, float wspeed)
+{
+ return 35.74 + 0.6215 * temp - 35.75 * powf(wspeed, 0.16) + 0.4275 * temp * powf(wspeed, 0.16);
+}
+/// <summary>
+/// Outputs the 3 inputs with format
+/// </summary>
+/// <param name="temp"></param>
+/// <param name="wspeed"></param>
+/// <param name="wchill"></param>
+void outputdata(float temp, float wspeed, float wchill)
+{
+ cout << "Temperature: " << temp << "F" << endl;
+ cout << "Wind speed: " << wspeed << "mph" << endl;
+ cout << "Wind chill: " << wchill << endl;
+} \ No newline at end of file