diff options
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 113 |
1 files changed, 109 insertions, 4 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..e4b294e 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -2,15 +2,120 @@ // #include <iostream> +#include <iomanip> +#include <string> +#include <cmath> using namespace std; -using std::cout; -using std::cin; -using std::endl; +float tempCelsius; +float tempFahrenheit; +float windSpeed; + +const float minF = -80.0, maxF = 121.0, minC = -62.0, maxC = 49.5; + +float ConvertTemperature(float temperature, char initialSystem) { + + // If initialSystem is 'C', temperature is converted into fahrenheit. If initialSystem is 'F', temperature is converted into celsius. + + float convertedTemp; + + switch(initialSystem) { + + case 'C': + // Converting celsius to fahrenheit, return the result. + + convertedTemp = (temperature * 1.8) + 32.0; + return convertedTemp; + + case 'F': + // Converting fahrenheit to celsius, return the result. + + convertedTemp = (temperature - 32.0) / 1.8; + return convertedTemp; + } + +} int main() { - cout << "Hello World!\n"; + cout << "Please enter a temperature between -80 to 121 degrees fahrenheit, or -62 and 49.5 degrees celsius." << endl; + cout << "Example entries: -32.3 F, 27.8 C" << endl; + + float tempInput; + char tempSystem; + + bool validEntries = false; + + do { + + cin >> tempInput >> tempSystem; + + if (tempSystem == 'C') { + + if (tempInput < minC || tempInput > maxC) { + + cout << "\nTemperature in celsius must be between -62 and 49.5 degrees. Please try again." << endl; + + } + else { + validEntries = true; + tempCelsius = tempInput; + tempFahrenheit = ConvertTemperature(tempInput, 'C'); + } + + } + else if (tempSystem == 'F') { + + if (tempInput < minF || tempInput > maxF) { + + cout << "\nTemperature in fahrenheit must be between -80 and 121 degrees. Please try again." << endl; + + } + else { + validEntries = true; + tempFahrenheit = tempInput; + tempCelsius = ConvertTemperature(tempInput, 'F'); + } + + } + else { + + cout << "\nInvalid temperature system. Please try again with C or F as your unit." << endl; + + } + + } while (validEntries == false); + + cout << "\nNext, enter a wind speed between 0 and 231mph. You do not need to include a unit." << endl; + + validEntries = false; + + do { + + cin >> windSpeed; + + if (windSpeed < 0 || windSpeed > 231) { + + cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl; + } + else { + validEntries = true; + } + + } while (validEntries == false); + + int colWidth = 20; + + float windChill = 35.74 + (0.6215 * tempFahrenheit) + (pow(windSpeed, 0.16) * ((0.4275 * tempFahrenheit) - 35.75)); + + cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl; + + cout << setprecision(2) << fixed << left; + cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << endl; + cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windChill << endl; + + return 0; + } |