summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortafaar <[email protected]>2022-11-08 18:00:03 -0800
committertafaar <[email protected]>2022-11-08 18:00:03 -0800
commit5ae08c6ec678e7d121295fe17063ee0d773e7a69 (patch)
tree15edfab07b1f67839cca0ca4f3049af367677c7c
parentfinished windchill function (diff)
downloadcst116-lab2-hill-5ae08c6ec678e7d121295fe17063ee0d773e7a69.tar.xz
cst116-lab2-hill-5ae08c6ec678e7d121295fe17063ee0d773e7a69.zip
formatting editing
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index 2fdbd15..a110688 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -12,7 +12,7 @@ float tempCelsius, windCelsius;
float tempFahrenheit, windFahrenheit;
float windSpeed;
-const float minF = -80.0, maxF = 121.0, minC = -62.0, maxC = 49.5;
+const float minF = -80.0, maxF = 121.0, minC = -62.0, maxC = 49.5, minW = 0, maxW = 231;
float ConvertTemperature(float temperature, char initialSystem) {
@@ -39,7 +39,7 @@ float ConvertTemperature(float temperature, char initialSystem) {
bool CheckWindSpeed(float& input) {
- if (input < 0 || input > 231) {
+ if (input < minW || input > maxW) {
cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl;
return false;
@@ -49,12 +49,15 @@ bool CheckWindSpeed(float& input) {
}
-void CalculateWindChill() {
+float GetWindChill() {
// Simply calculates the wind chill in fahrenheit, and converts it to celsius using a previous function
- windFahrenheit = 35.74 + (0.6215 * tempFahrenheit) + (pow(windSpeed, 0.16) * ((0.4275 * tempFahrenheit) - 35.75));
- windCelsius = ConvertTemperature(windFahrenheit, 'F');
+ float windChill;
+
+ windChill = 35.74 + (0.6215 * tempFahrenheit) + (pow(windSpeed, 0.16) * ((0.4275 * tempFahrenheit) - 35.75));
+
+ return windChill;
}
@@ -120,15 +123,16 @@ int main()
} while (validEntries == false);
- int colWidth = 20;
+ windFahrenheit = GetWindChill();
+ windCelsius = ConvertTemperature(windFahrenheit, 'F');
- float windChill;
+ int colWidth = 20;
cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl;
- cout << setprecision(1) << fixed << left;
+ cout << setprecision(2) << fixed << left;
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) << windChill << setw(colWidth) << ConvertTemperature(windChill, 'F') << endl;
+ cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windFahrenheit << setw(colWidth) << windCelsius << endl;
return 0;