diff options
| author | Andrei F <[email protected]> | 2022-11-09 16:00:13 -0800 |
|---|---|---|
| committer | Andrei F <[email protected]> | 2022-11-09 16:00:13 -0800 |
| commit | 6114e1432cdfcacf530981468e532a7faa016173 (patch) | |
| tree | b98cb84ccb31f7a0e1d5a72d7d20d8c870888ba8 | |
| parent | Setting up GitHub Classroom Feedback (diff) | |
| download | cst116-lab2-florea-6114e1432cdfcacf530981468e532a7faa016173.tar.xz cst116-lab2-florea-6114e1432cdfcacf530981468e532a7faa016173.zip | |
First commit
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.cpp | 86 | ||||
| -rwxr-xr-x | a.out | bin | 0 -> 42018 bytes |
2 files changed, 83 insertions, 3 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index ed5f807..b9db15f 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -1,5 +1,6 @@ -// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +/* +Andrei Florea - CST 116 - Lab 2 - Calculating wind chill +*/ #include <iostream> @@ -9,8 +10,87 @@ 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); + +const int F_MAX = 121; +const int F_MIN = -80; + +const float C_MAX = 42.5; +const int C_MIN = -62; + +const int W_MAX = 231; +const int W_MIN = 0; + int main() { - cout << "Hello World!\n"; + // Driver function for the program + int temperature = -100; + int wind_speed = -100; + int chill; + char temp_decision; + + cout << "Do you want to input temperature in Farenheit (F) or Celsius (C)?" << endl; + cin >> temp_decision; + temp_decision = tolower(temp_decision); + + + user_entry_temp(temperature, temp_decision); + + + cout << temperature; + +} + +void user_entry_temp(int& temperature, char decision) +{ + // Takes argument by reference and limits the input to a specific range for temperature, doesn't return, it changes by reference + + if (decision != 'f' && decision != 'c') // Ensures that the temp_decision is either f or c. + { + while (decision != 'f' && decision != 'c') + { + cout << "Wrong input for temperature, do you want temperature in Farenheit (F) or Celsius (C)?" << endl; + cin >> decision; + decision = tolower(decision); + } + } + + if (decision == 'c') + { + while (temperature < C_MIN || temperature > C_MAX) // Ensures input for temperature is within the range + { + 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 + + } + 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; + cin >> temperature; + } + } } +void user_entry_speed(int& wind_speed) +{ + // Takes user input for wind_speed and makes sure its within the given range, doesn't return it changes by reference + + while (wind_speed < W_MIN || wind_speed > W_MAX) + { + cout << "Enter a speed for the wind in MPH (0 - 231, inclusive): " << endl; + cin >> wind_speed; + } +} + +int convert_to_f(int c_temp) +{ + // Takes input in celsius, and will convert it to farenheit, returns converted temp + c_temp = 1.8 * c_temp + 32; + return c_temp; +} Binary files differ |