summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
diff options
context:
space:
mode:
authortafaar <[email protected]>2022-11-08 18:09:34 -0800
committertafaar <[email protected]>2022-11-08 18:09:34 -0800
commit6bd1e020952a2c6b650ffbacdd0ad726a7c2935c (patch)
tree8cdc1fef7cc47fb005142f4aa82b4f108cd5001b /BlankConsoleLab/BlankConsoleLab.cpp
parentCleaned up variable declaration (diff)
downloadarchived-cst116-lab2-hill-6bd1e020952a2c6b650ffbacdd0ad726a7c2935c.tar.xz
archived-cst116-lab2-hill-6bd1e020952a2c6b650ffbacdd0ad726a7c2935c.zip
renamed solution
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp155
1 files changed, 0 insertions, 155 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
deleted file mode 100644
index 8221ee7..0000000
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
-#include <iostream>
-#include <iomanip>
-#include <string>
-#include <cmath>
-
-using namespace std;
-
-float tempCelsius, windCelsius;
-float tempFahrenheit, windFahrenheit;
-float windSpeed;
-
-// Constants for the range of acceptable temperatures and wind speed.
-
-const float minF = -80.0, maxF = 121.0;
-const float minC = -62.0, maxC = 49.5;
-const float minW = 0, maxW = 231;
-
-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;
- }
-
-}
-
-bool CheckWindSpeed(float& input) {
-
- // Checks to see if the value entered is between the minimum and maximum wind speeds.
-
- if (input < minW || input > maxW) {
-
- cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl;
- return false; // Returns false if the value is beyond or below the range.
-
- }
- else return true;
-
-}
-
-float GetWindChill() {
-
- // Simply calculates the wind chill in fahrenheit, and converts it to celsius using a previous function
-
- float windChill;
-
- windChill = 35.74 + (0.6215 * tempFahrenheit) + (pow(windSpeed, 0.16) * ((0.4275 * tempFahrenheit) - 35.75));
-
- return windChill; // Returns the wind chill based on what the user entered before the function has been called. Only outputs as fahrenheit.
-
-}
-
-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;
-
- float tempInput;
- char tempSystem;
-
- bool validEntries = false;
-
- // 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.
-
- 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 is just a boolean that's getting reused.
-
- validEntries = false;
-
- do {
-
- cin >> windSpeed;
-
- validEntries = CheckWindSpeed(windSpeed); // If the user's input is between the minium and maximum wind speeds, this will return true.
-
- } while (validEntries == false);
-
- // Setting the wind chill values.
-
- windFahrenheit = GetWindChill();
- windCelsius = ConvertTemperature(windFahrenheit, 'F');
-
- int colWidth = 20;
-
- cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl;
-
- // Printing the table.
-
- 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;
-
-}
-