// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // // Name: Taylor Rogers // Assignment: Lab 2 // // Pseudo Code: // 1. Print "Please enter F for Fahrenheit, or C for Celsius" // 1. Declare constant [Fmax] = 121 // 2. Declare constant [Fmin] = -80 // 3. Declare constant [Cmax] = 49.5 // 4. Declare constant [Cmin] = -62 // 2. Input [Tunit] // 3. If [Tunit] = F is selected: // 1. Print "Enter temperature value between -80 and 121 degrees Fahreneit" // 2. Input [TvalF] // 3. Clamp TvalF to limits // 4. If [Tunit] = C is selected: // 1. Print "Enter temperature value between -52 and 49.5 degrees Celsius" // 2. Input [TvalC] // 3. Clamp TvalC to limits // 6. Print "Enter a wind speed, in miles per hour, between 0 and 231" // 1. Declare constant [Wmax] = 231 // 2. Declare constant [Wmin] = 0 // 3. Input [Wspeed] // 4. Clamp Wspeed to limits // 7. F input function: // 1. Declare [FtoCval] = ( [TvalF] - 32 ) * ( 5 / 9 ) // 2. [TvalC] = [FtoCval] // 8. C input function: // 1. Declare [CtoFval] = (9 / 5 ) * [TvalC] + 32 // 2. [TvalF] = [CtoFval] // 9. Windchill function: // 1. [Wchill] = 35.74 + .6215 * [TvalF] - 35.75 * ( [Wspeed] ^ 0.16 ) + 0.4275 * [TvalF] * ( [Wspeed] ^ 0.16 ) // 10. Print headers "Temperature in F" , "Temperature in C", "Windpseed", "Windchill" // 11. Print [TvalF] , [TvalC] , [Wspeed] , [Wchill] // #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; if (TvalF > Fmax) { TvalF = Fmax; cout << "Value set to " << Fmax << "F." << endl; } else if (TvalF < Fmin) { TvalF = Fmin; cout << "Value set to " << Fmin << "F." << endl; } FtoCfunc(TvalC); } // Temp input in C else if (Tunit == 67) { cout << "Please enter temperature between " << Cmin << " and " << Cmax << " degrees C: "; cin >> TvalC; if (TvalC > Cmax) { TvalC = Cmax; cout << "Value set to " << Cmax << "C." << endl; } else if (TvalC < Cmin) { TvalC = Cmin; cout << "Value set to " << Cmin << "C." << 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; if (Wspeed > Wmax) { Wspeed = Wmax; cout << "Value set to " << Wmax << "MPH." << endl; } else if (Wspeed < Wmin) { Wspeed = Wmin; cout << "Value set to " << Wmin << "MPH." << endl; } Wchfunc(Wchill); cout << endl; cout << setw(20) << "Temp in C" << setw(20) << "Temp in F" << setw(20) << "Wind Speed" << setw(20) << "Wind Chill" << endl; cout << setw(20) << TvalC << setw(20) << TvalF << setw(20) << Wspeed << setw(20) << Wchill << endl; cout << endl; }