summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authortafaar <[email protected]>2022-11-08 17:37:18 -0800
committertafaar <[email protected]>2022-11-08 17:37:18 -0800
commitba2e04d093fa7560b990d989c976718112dd7959 (patch)
tree500001f2cac96188df7dcd1cf03c3786d72a1559 /BlankConsoleLab
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab2-hill-ba2e04d093fa7560b990d989c976718112dd7959.tar.xz
cst116-lab2-hill-ba2e04d093fa7560b990d989c976718112dd7959.zip
wrote most of the program
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp113
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
2 files changed, 113 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..e4b294e 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -2,15 +2,120 @@
//
#include <iostream>
+#include <iomanip>
+#include <string>
+#include <cmath>
using namespace std;
-using std::cout;
-using std::cin;
-using std::endl;
+float tempCelsius;
+float tempFahrenheit;
+float windSpeed;
+
+const float minF = -80.0, maxF = 121.0, minC = -62.0, maxC = 49.5;
+
+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;
+ }
+
+}
int main()
{
- cout << "Hello World!\n";
+ 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" << endl;
+
+ float tempInput;
+ char tempSystem;
+
+ bool validEntries = false;
+
+ 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 = false;
+
+ do {
+
+ cin >> windSpeed;
+
+ if (windSpeed < 0 || windSpeed > 231) {
+
+ cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl;
+ }
+ else {
+ validEntries = true;
+ }
+
+ } while (validEntries == false);
+
+ int colWidth = 20;
+
+ float windChill = 35.74 + (0.6215 * tempFahrenheit) + (pow(windSpeed, 0.16) * ((0.4275 * tempFahrenheit) - 35.75));
+
+ cout << "\nConversions for " << tempInput << tempSystem << " with wind speed " << windSpeed << "MPH." << endl;
+
+ cout << setprecision(2) << fixed << left;
+ cout << setw(colWidth) << "\nCelsius" << setw(colWidth) << "Fahrenheit" << setw(colWidth) << "Wind Speed" << setw(colWidth) << "Wind Chill (F)" << endl;
+ cout << setw(colWidth) << tempCelsius << setw(colWidth) << tempFahrenheit << setw(colWidth) << windSpeed << setw(colWidth) << windChill << endl;
+
+ return 0;
+
}
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index db2e734..d2e3ee2 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>