// CST116-lab2-joetraver30.cpp #include #include #include using std::cout; using std::cin; using std::endl; void GetInfo(char& letter, float& t, float& T, int& W); float FahrenheitConversion(float T); float WindChillCalculation(int W, float t); int main() { char letter = {}; float T = 0; int W = 0; float t = 0; float C = 0; GetInfo(letter, t, T, W); if (letter == 'c' || letter == 'C') t = FahrenheitConversion(T); cout << "Temperature is: " << t << " Degrees Fahrenheit" << endl << endl; cout << "Wind speed is: " << W << " MPH" << endl << endl; C = WindChillCalculation(W, t); cout << "For " << t << " degrees F and " << W << " MPH, the windchill is: " << C << endl; } //compiles information from the user void GetInfo(char& letter, float& t, float& T, int& W) { //ask for type of temp unids that need to be used cout << "Enter temperature units Celcius or Fahrenheit (C/F): "; cin >> letter; cout << endl; //error check while (!((letter == 'c') || (letter == 'C') || (letter == 'f') || (letter == 'F'))) { cout << "ERROR: a F or C must be entered"; cin.clear(); cin.ignore(); cout << endl << endl; cout << "Enter temperature units Celcius or Fahrenheit (C/F): "; cin >> letter; cout << endl; } if (letter == 'c' || letter == 'C') { //ask for temp in C cout << "Enter the temperature in Celcuius between -62 degrees & 49.5 degrees: "; cin >> T; cout << endl; //Bounds check while (!((T >= -62) && (T <= 49.5F))) { cout << "Temperature lies outside of accepted bounds" << endl; cin.clear(); cin.ignore(); cout << endl; cout << "Enter the temperature in Celcuius between -62 degrees & 49.5 degrees: "; cin >> T; cout << endl; } } else { //ask for temp in F cout << "Enter the temperature in Fahrtenheit beteen -80 degrees & 121 degrees: "; cin >> t; cout << endl; //Bounds check while (!((t >= -80) && (t <= 121))) { cout << "Temperature lies outside of accepted bounds" << endl; cin.clear(); cin.ignore(); cout << endl; cout << "Enter the temperature in Fahrtenheit beteen -80 degrees & 121 degrees: "; cin >> t; cout << endl; } } // requests wind speed cout << "Enter wind speed between 0 MPH & 231 MPH: "; cin >> W; cout << endl; //Bounds check while (!((W >= 0) && (W <= 231))) { cout << "Wind speed lies outside of accepted bounds" << endl; cin.clear(); cin.ignore(); cout << endl; cout << "Enter wind speed between 0 MPH & 231 MPH: "; cin >> W; cout << endl; } } //Fahrenheit Conversion Function that returns a floating value float FahrenheitConversion(float T) { return (((9.0F / 5) * T) + 32); } //wind chill calculation that returns a floating value float WindChillCalculation(int W, float t) { return (35.74F + 0.6215F * t - 35.75 * (pow(W, 0.16F)) + 0.4275F * t * (pow(W, 0.16F))); }