summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/Lab2TrevorBouchillon.cpp
blob: b3d9a59ed7118e64ec5b3292412250112aa3a353 (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
// 
// Lab2
// Trevor Bouchillon
// CST116
//

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

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

float UserInputTemp;
float WindSpeed;
char CorF;
float windchill;


float CelciusToFarenheit(float Celcius2Farenheit) {                                   //function to turn celcius entries into farenheit. 
    Celcius2Farenheit = (UserInputTemp * (static_cast<float>(9) / 5)) + 32;
    return Celcius2Farenheit;
}
 
float GetTemp() {                                                                     //function to collect temperature inputs
    cout << "Please enter a temperature in Celcius or Farenheit: ";
    cin >> UserInputTemp;
    cout << "If you entered a temperature in Celcius please enter 'C' and if you entered a temperature in Farenheit please enter 'F'. ";
    cin >> CorF;

    while (CorF != 'C' && CorF != 'F') {
        cout << "Please enter either 'C' or 'F': ";
        cin >> CorF;
    }
    if (CorF == 'F') {
        while (UserInputTemp < -80 || UserInputTemp > 121) {
            cout << "Please enter a temperature between -80 and 121." << endl;
            cout << "Please enter a temperature in Farenheit: ";
            cin >> UserInputTemp;
        }
    }
    else if (CorF == 'C') {
        while (UserInputTemp < -62 || UserInputTemp > 49.5) {
            cout << "Please enter a temperature between -62 and 49.5." << endl;
            cout << "Please enter a temperature in Celcius: ";
            cin >> UserInputTemp;
        }
        cout << "The temperature you entered is " << CelciusToFarenheit(UserInputTemp) << " degrees in Farenheit." << endl;
    }
    return UserInputTemp;
}

float GetWindSpeed() {                                                          //function to collect windspeed inputs
    cout << "Please enter a wind speed in Miles Per Hour: ";
    cin >> WindSpeed;
    while (WindSpeed < 0 || WindSpeed > 231) {
        cout << "Please enter a wind speed between 0 and 231 Miles Per Hour" << endl;
        cout << "Please enter a wind speed in Miles Per Hour: ";
        cin >> WindSpeed;
    }
    return WindSpeed;
}

float WindChill() {                                                              //function to calculate windchill
    windchill = 35.74 + (0.6215 * CelciusToFarenheit(UserInputTemp)) - (35.75 * pow(WindSpeed, 0.16)) + (0.4275 * CelciusToFarenheit(UserInputTemp) * pow(WindSpeed, 0.16));
    cout << "Based on your inputs of " << CelciusToFarenheit(UserInputTemp) << " and " << WindSpeed << ", the wind chill is " << windchill << ".";
    return windchill;
}

int main()
{
    GetTemp();
    GetWindSpeed();
    WindChill();
    
    return 0;
}