// 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; 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 convertCelsiustoFahrenheit(float& celciusvalue); float WindChillcalc(float temp, float wspeed); void outputdata(float temp, float wspeed, float wchill); int main() { 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) convertCelsiustoFahrenheit(temp); while ((MinW > wspeed) || (MaxW < wspeed)) { cout << "Input a wind speed in 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 convertCelsiustoFahrenheit(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; }