// 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() { char continu = 'Y'; while (continu == 'Y') { // Temp unit selection cout << "Please enter F for Fahrenheit or C for Celsius: "; cin >> Tunit; cout << endl; // Temp input in F if (Tunit == 70 || Tunit == 102) { cout << "Please enter temperature between " << Fmin << " and " << Fmax << " degrees F: "; cin >> TvalF; cout << endl; while (TvalF < Fmin || TvalF > Fmax) { cout << "Please enter a value between " << Fmin << " and " << Fmax << ": "; cin >> TvalF; } FtoCfunc(TvalC); } // Temp input in C else if (Tunit == 67 || Tunit == 99) { cout << "Please enter temperature between " << Cmin << " and " << Cmax << " degrees C: "; cin >> TvalC; cout << endl; while (TvalC < Cmin || TvalC > Cmax) { cout << "Please enter a value between " << Cmin << " and " << Cmax << ": "; cin >> TvalC; } CtoFfunc(TvalF); } else { cout << "Invalid unit" << endl; return 0; } //Windspeed cout << "Please enter a windpeed value between 0 and 231 in Miles Per Hour: "; cin >> Wspeed; cout << endl; while (Wspeed < Wmin || Wspeed > Wmax) { cout << "Please enter a value between " << Wmin << " and " << Wmax << ": "; cin >> Wspeed; } 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; cout << "Want to do again? Type \'Y\': "; cin >> continu; } }