summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: a008590069da96dcbf999ae7362b03e7138c76b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 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;
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;
    }

}

bool CheckWindSpeed(float& input) {

    if (input < 0 || input > 231) {

        cout << "\nInvalid wind speed. Please enter a number between 0 and 231" << endl;
        return false;

    }
    else return true;

}

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;

    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;

        validEntries = CheckWindSpeed(windSpeed);

    } 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(1) << 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;

    return 0;

}