summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: e85f9d9bc42b9e23cc534cd19d538b3f82f706e0 (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
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <cmath>

using namespace std;

using std::cout;
using std::cin;
using std::endl;
using std::pow;

int selectType();
float getTemp(int& select);
float calcTemp(float& temp);
float getWindSpeed();
void calcWindChill(float temp, float windSpeed);

int main()
{
    float temp;
    int select = 0;
    float windSpeed = 0;

    select = selectType();
    temp = getTemp(select);
    if (select == 2)
        temp = calcTemp(temp);
    windSpeed = getWindSpeed();

    calcWindChill(temp, windSpeed);

    return 0;
}
int selectType()
{
    char choose = '0';
    int select = 0;

    while (select != 1 && select != 2)
    {
        cout << "Enter temperature in Fahrenheit or Celsius?" << endl << "[1] Fahrenheit" << endl << "[2] Celsius" << endl;
        cout << "Selection: ";
        cin >> choose;

        if (choose == '1')
            select = 1;
        else if (choose == '2')
            select = 2;
        else cout << "Please enter only 1 or 2." << endl;
    }

    return select;
}
float getTemp(int& select)
{
    float temp = 0;
    const int minC = -62;
    const int maxC = 49.5;
    const int minF = -80;
    const int maxF = 121;

    if (select == 1)
    {
        while (temp >= minC && temp <= maxC)
        {
            cout << endl << "Enter temperature: ";
            cin >> temp;

            if (temp < minC || temp > maxC)
                cout << endl << "Please enter between " << minC << " and " << maxC << endl;
        }
    }

    if (select == 2)
    {
        while (temp >= minF && temp <= maxF)
        {
            cout << endl << "Enter temperature: ";
            cin >> temp;

            if (temp < minF || temp > maxF)
                cout << endl << "Please enter between " << minF << " and " << maxF << endl;
        }
    }

    return temp;
}
float calcTemp(float& Celsius)
{
    float Fahrenheit = 0;

    Fahrenheit = (9 / 5) * Celsius + 32;

    return Fahrenheit;
}
float getWindSpeed()
{
    float windSpeed = 0;

    cout << endl << "Enter wind speed in MPH: ";
    cin >> windSpeed;

    return windSpeed;
}
void calcWindChill(float temp, float windSpeed)
{
    float windChill = 0;

    windChill = 35.74 + 0.6215 * temp - 35.75 * pow(windSpeed, 0.16) + 0.4275 * temp * pow(windSpeed, 0.16);

    cout << endl << windChill;
}