diff options
| author | Aaron Hill <[email protected]> | 2022-11-09 15:42:00 -0800 |
|---|---|---|
| committer | Aaron Hill <[email protected]> | 2022-11-09 15:42:00 -0800 |
| commit | 4b069f811f8f7d38bac410325da770a487f6baf0 (patch) | |
| tree | 5e6c5c323e1e418818980cd49e8dcc700140de3b /BlankConsoleLab/CST116 -Lab2-Hill.cpp | |
| parent | added flowchart (diff) | |
| download | cst116-lab2-hill-4b069f811f8f7d38bac410325da770a487f6baf0.tar.xz cst116-lab2-hill-4b069f811f8f7d38bac410325da770a487f6baf0.zip | |
added choice to continue
Diffstat (limited to 'BlankConsoleLab/CST116 -Lab2-Hill.cpp')
| -rw-r--r-- | BlankConsoleLab/CST116 -Lab2-Hill.cpp | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/BlankConsoleLab/CST116 -Lab2-Hill.cpp b/BlankConsoleLab/CST116 -Lab2-Hill.cpp index 8221ee7..81d82ec 100644 --- a/BlankConsoleLab/CST116 -Lab2-Hill.cpp +++ b/BlankConsoleLab/CST116 -Lab2-Hill.cpp @@ -69,85 +69,94 @@ float GetWindChill() { int main() { - 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\n" << endl; + char choice = 'n'; - float tempInput; - char tempSystem; + while (choice != 'Y') { - bool validEntries = false; + 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\n" << endl; - // Taking input from the user until they give a valid entry. - // A valid entry should be a number and the character C for celsius or F for fahrenheit. + float tempInput; + char tempSystem; - do { - - cin >> tempInput >> tempSystem; + bool validEntries = false; - if (tempSystem == 'C') { + // Taking input from the user until they give a valid entry. + // A valid entry should be a number and the character C for celsius or F for fahrenheit. - if (tempInput < minC || tempInput > maxC) { + do { - cout << "\nTemperature in celsius must be between -62 and 49.5 degrees. Please try again." << endl; + 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 { - validEntries = true; - tempCelsius = tempInput; - tempFahrenheit = ConvertTemperature(tempInput, 'C'); - } + else if (tempSystem == 'F') { - } - else if (tempSystem == 'F') { + if (tempInput < minF || tempInput > maxF) { - if (tempInput < minF || tempInput > maxF) { + cout << "\nTemperature in fahrenheit must be between -80 and 121 degrees. Please try again." << endl; - 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 { - validEntries = true; - tempFahrenheit = tempInput; - tempCelsius = ConvertTemperature(tempInput, 'F'); - } - } - else { + cout << "\nInvalid temperature system. Please try again with C or F as your unit." << endl; + + } - 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; - } while (validEntries == false); + // validEntries is just a boolean that's getting reused. - cout << "\nNext, enter a wind speed between 0 and 231mph. You do not need to include a unit." << endl; + validEntries = false; - // validEntries is just a boolean that's getting reused. + do { - validEntries = false; + cin >> windSpeed; - do { + validEntries = CheckWindSpeed(windSpeed); // If the user's input is between the minium and maximum wind speeds, this will return true. - cin >> windSpeed; + } while (validEntries == false); - validEntries = CheckWindSpeed(windSpeed); // If the user's input is between the minium and maximum wind speeds, this will return true. + // Setting the wind chill values. - } while (validEntries == false); + windFahrenheit = GetWindChill(); + windCelsius = ConvertTemperature(windFahrenheit, 'F'); - // Setting the wind chill values. + int colWidth = 20; - windFahrenheit = GetWindChill(); - windCelsius = ConvertTemperature(windFahrenheit, 'F'); + cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl; - int colWidth = 20; + // Printing the table. - cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl; + cout << setprecision(2) << fixed << left << setw(20); + cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << setw(colWidth) << "Wind Chill (C)" << endl; + cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windFahrenheit << setw(colWidth) << windCelsius << endl; - // Printing the table. + cout << "\nIf you would like to input another set of data, please enter 'Y'" << endl; + cin >> choice; - cout << setprecision(2) << fixed << left << setw(20); - cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << setw(colWidth) << "Wind Chill (C)" << endl; - cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windFahrenheit << setw(colWidth) << windCelsius << endl; + } return 0; |