// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // // Name: Taylor Rogers // Assignment: Lab 2 // #include #include #include using std::cout; using std::cin; using std::endl; using std::setw; const int Fmax = 121; signed const int Fmin = -80; const int Cmax = 49.5; signed const int Cmin = -62; const int Wmax = 231; const int Wmin = 0; char Tunit{}; float TvalF{}; float TvalC{}; int Wspeed{}; float Wchill{}; // Converts Fahrenheit to Celsius float FtoCfunc(float FtoCval) { FtoCval = 0; FtoCval = (TvalF - 32) * (5.0f / 9.0f); TvalC = FtoCval; return TvalC; } // Converts Celsius to Fahrenheit float CtoFfunc(float CtoFval) { CtoFval = 0; CtoFval = (9.0f / 5.0f) * TvalC + 32; TvalF = CtoFval; return TvalF; } // Converts Windspeed and Temp to Winchill float Wchfunc(float& Wchcalc) { Wchcalc = 0; Wchcalc = 35.74f + .6215f * TvalF - 35.75f * (pow(Wspeed, 0.16f)) + 0.4275f * TvalF * (pow(Wspeed, 0.16f)); Wchill = Wchcalc; return Wchill; } int main() { // Temp unit selection cout << "Please enter F for Fahrenheit or C for Celsius: "; cin >> Tunit; cout << endl; // Temp input in F if (Tunit == 70) { cout << "Please enter temperature between " << Fmin << " and " << Fmax << " degrees F: "; cin >> TvalF; cout << endl; if (TvalF > Fmax) { TvalF = Fmax; cout << "Value set to " << Fmax << "F." << endl; cout << endl; } else if (TvalF < Fmin) { TvalF = Fmin; cout << "Value set to " << Fmin << "F." << endl; cout << endl; } FtoCfunc(TvalC); } // Temp input in C else if (Tunit == 67) { cout << "Please enter temperature between " << Cmin << " and " << Cmax << " degrees C: "; cin >> TvalC; cout << endl; if (TvalC > Cmax) { TvalC = Cmax; cout << "Value set to " << Cmax << "C." << endl; cout << endl; } else if (TvalC < Cmin) { TvalC = Cmin; cout << "Value set to " << Cmin << "C." << endl; cout << endl; } CtoFfunc(TvalF); } else cout << "Invalid unit" << endl; //Windspeed cout << "Please enter a windpeed value between 0 and 231 in Miles Per Hour: "; cin >> Wspeed; cout << endl; if (Wspeed > Wmax) { Wspeed = Wmax; cout << "Value set to " << Wmax << "MPH." << endl; cout << endl; } else if (Wspeed < Wmin) { Wspeed = Wmin; cout << "Value set to " << Wmin << "MPH." << endl; cout << endl; } Wchfunc(Wchill); cout << endl; cout << setw(25) << "Temp (C)" << setw(25) << "Temp (F)" << setw(25) << "Wind Speed (MPH)" << setw(25) << "Wind Chill" << endl; cout << setw(25) << TvalC << setw(25) << TvalF << setw(25) << Wspeed << setw(25) << Wchill << endl; cout << endl; }