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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// CST116-lab2-joetraver30.cpp
#include <iostream>
#include <math.h>
#include <stdio.h>
using std::cout;
using std::cin;
using std::endl;
void GetInfo(char& letter, float& t, float& T, int& W);
float FahrenheitConversion(float T);
float WindChillCalculation(int W, float t);
int main()
{
char letter = {};
float T = 0;
int W = 0;
float t = 0;
float C = 0;
GetInfo(letter, t, T, W);
if (letter == 'c' || letter == 'C')
t = FahrenheitConversion(T);
cout << "Temperature is: " << t << " Degrees Fahrenheit" << endl << endl;
cout << "Wind speed is: " << W << " MPH" << endl << endl;
C = WindChillCalculation(W, t);
cout << "For " << t << " degrees F and " << W << " MPH, the windchill is: " << C << endl;
}
//compiles information from the user
void GetInfo(char& letter, float& t, float& T, int& W)
{
//ask for type of temp unids that need to be used
cout << "Enter temperature units Celcius or Fahrenheit (C/F): ";
cin >> letter;
cout << endl;
//error check
while (!((letter == 'c') || (letter == 'C') || (letter == 'f') || (letter == 'F')))
{
cout << "ERROR: a F or C must be entered";
cin.clear();
cin.ignore();
cout << endl << endl;
cout << "Enter temperature units Celcius or Fahrenheit (C/F): ";
cin >> letter;
cout << endl;
}
if (letter == 'c' || letter == 'C')
{
//ask for temp in C
cout << "Enter the temperature in Celcuius between -62 degrees & 49.5 degrees: ";
cin >> T;
cout << endl;
//Bounds check
while (!((T >= -62) && (T <= 49.5F)))
{
cout << "Temperature lies outside of accepted bounds" << endl;
cin.clear();
cin.ignore();
cout << endl;
cout << "Enter the temperature in Celcuius between -62 degrees & 49.5 degrees: ";
cin >> T;
cout << endl;
}
}
else
{
//ask for temp in F
cout << "Enter the temperature in Fahrtenheit beteen -80 degrees & 121 degrees: ";
cin >> t;
cout << endl;
//Bounds check
while (!((t >= -80) && (t <= 121)))
{
cout << "Temperature lies outside of accepted bounds" << endl;
cin.clear();
cin.ignore();
cout << endl;
cout << "Enter the temperature in Fahrtenheit beteen -80 degrees & 121 degrees: ";
cin >> t;
cout << endl;
}
}
cout << "Enter wind speed between 0 MPH & 231 MPH: ";
cin >> W;
cout << endl;
//Bounds check
while (!((W >= 0) && (W <= 231)))
{
cout << "Wind speed lies outside of accepted bounds" << endl;
cin.clear();
cin.ignore();
cout << endl;
cout << "Enter wind speed between 0 MPH & 231 MPH: ";
cin >> W;
cout << endl;
}
}
//Fahrenheit Conversion Function that returns a floating value
float FahrenheitConversion(float T)
{
return (((9.0F / 5) * T) + 32);
}
//wind chill calculation that returns a floating value
float WindChillCalculation(int W, float t)
{
return (35.74F + 0.6215F * t - 35.75 * (pow(W, 0.16F)) + 0.4275F * t * (pow(W, 0.16F)));
}
|