From 038edda00013f202235479f5ef337010f1d94f80 Mon Sep 17 00:00:00 2001 From: CEOofOogaBooga Date: Tue, 8 Nov 2022 20:53:23 -0800 Subject: Finished 1.0 --- BlankConsoleLab/BlankConsoleLab.cpp | 95 ++++++++++++++++++++++++++++++++++--- 1 file 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 - +#include 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; +} +/// +/// Changes the reference celciusvalue to fahrenheit +/// +/// +void converCelsiustoFahrenheit(float& celciusvalue) +{ + celciusvalue * (9.0 / 5.0); + celciusvalue + 32; +} +/// +/// Calculates the wind chill and returns it from the temperature and wind speed +/// +/// +/// +/// +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); +} +/// +/// Outputs the 3 inputs with format +/// +/// +/// +/// +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 -- cgit v1.2.3