summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei F <[email protected]>2022-11-09 16:13:11 -0800
committerAndrei F <[email protected]>2022-11-09 16:13:11 -0800
commit079146e2275a2efb19daa800c6794c2f26897a66 (patch)
treeeb10f47852d233b4ced2054da04ab4e785ae8aeb
parentFirst commit (diff)
downloadcst116-lab2-florea-079146e2275a2efb19daa800c6794c2f26897a66.tar.xz
cst116-lab2-florea-079146e2275a2efb19daa800c6794c2f26897a66.zip
Finished code
-rw-r--r--BlankConsoleLab/CST116-Lab2-Florea.cpp (renamed from BlankConsoleLab/BlankConsoleLab.cpp)48
-rwxr-xr-xa.outbin42018 -> 42610 bytes
2 files changed, 33 insertions, 15 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/CST116-Lab2-Florea.cpp
index b9db15f..9603d61 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/CST116-Lab2-Florea.cpp
@@ -3,6 +3,7 @@ Andrei Florea - CST 116 - Lab 2 - Calculating wind chill
*/
#include <iostream>
+#include <math.h>
using namespace std;
@@ -10,9 +11,10 @@ using std::cout;
using std::cin;
using std::endl;
-void user_entry_temp(int& temperature, char decision);
-void wind_speed(int& wind_speed);
-int convert_to_f(int c_temp);
+void user_entry_temp(float& temperature, char decision);
+void user_entry_speed(float& wind_speed);
+float convert_to_f(float c_temp);
+float calculate_wind_chill(float temp, float wind);
const int F_MAX = 121;
const int F_MIN = -80;
@@ -26,24 +28,30 @@ const int W_MIN = 0;
int main()
{
// Driver function for the program
- int temperature = -100;
- int wind_speed = -100;
- int chill;
+ float temperature = -100;
+ float wind_speed = -100;
+ float chill;
char temp_decision;
- cout << "Do you want to input temperature in Farenheit (F) or Celsius (C)?" << endl;
+ cout << "Do you want to input temperature in Fahrenheit (F) or Celsius (C)?" << endl;
cin >> temp_decision;
temp_decision = tolower(temp_decision);
user_entry_temp(temperature, temp_decision);
+ user_entry_speed(wind_speed);
- cout << temperature;
+ chill = calculate_wind_chill(temperature, wind_speed);
+ temp_decision = toupper(temp_decision);
+
+ cout << "For " << temperature << " degrees " << temp_decision << " and " << wind_speed << " mph";
+ cout << " the wind chill is: " << chill;
+
}
-void user_entry_temp(int& temperature, char decision)
+void user_entry_temp(float& temperature, char decision)
{
// Takes argument by reference and limits the input to a specific range for temperature, doesn't return, it changes by reference
@@ -51,7 +59,7 @@ void user_entry_temp(int& temperature, char decision)
{
while (decision != 'f' && decision != 'c')
{
- cout << "Wrong input for temperature, do you want temperature in Farenheit (F) or Celsius (C)?" << endl;
+ cout << "Wrong input for temperature, do you want temperature in Fahrenheit (F) or Celsius (C)?" << endl;
cin >> decision;
decision = tolower(decision);
}
@@ -64,20 +72,23 @@ void user_entry_temp(int& temperature, char decision)
cout << "Enter a value in Celsius for temperature (-62C - 42.5C inclusive): " << endl;
cin >> temperature;
}
- temperature = convert_to_f(temperature); // Calls to convert temperature to Farenheit
+
+ cout << "You entered " << temperature << " degrees celsius." << endl;
+ temperature = convert_to_f(temperature); // Calls to convert temperature to Fahrenheit
}
else if (decision == 'f')
{
while (temperature < F_MIN || temperature > F_MAX) // Ensures input for temperature is within the range
{
- cout << "Enter a value in Farenheit for temperature (-80F - 121F inclusive): " << endl;
+ cout << "Enter a value in Fahrenheit for temperature (-80F - 121F inclusive): " << endl;
cin >> temperature;
}
+ cout << "You entered " << temperature << " degrees Fahrenheit." << endl;
}
}
-void user_entry_speed(int& wind_speed)
+void user_entry_speed(float& wind_speed)
{
// Takes user input for wind_speed and makes sure its within the given range, doesn't return it changes by reference
@@ -86,11 +97,18 @@ void user_entry_speed(int& wind_speed)
cout << "Enter a speed for the wind in MPH (0 - 231, inclusive): " << endl;
cin >> wind_speed;
}
+ cout << "You entered " << wind_speed << " miles per hour." << endl;
}
-int convert_to_f(int c_temp)
+float convert_to_f(float c_temp)
{
- // Takes input in celsius, and will convert it to farenheit, returns converted temp
+ // Takes input in celsius, and will convert it to Fahrenheit, returns converted temp
c_temp = 1.8 * c_temp + 32;
return c_temp;
}
+
+float calculate_wind_chill(float temp, float wind)
+{
+ // Takes the temperature and wind speed and calculates chill, returns float
+ return 35.74 + .6215 * temp - 35.75 * pow(wind, .16) + .4275 * temp * pow(wind, .16);
+}
diff --git a/a.out b/a.out
index 3ac37e9..0253058 100755
--- a/a.out
+++ b/a.out
Binary files differ