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
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using std::string;
using std::to_string;
using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
// Function name cToF, inputs a float a, returns a float temp
float cToF(float a) {
float temp = (9.0 / 5) * a + 32;
return temp;
}
// Function name windChill, inputs a float d, w, and boolean x by reference, returns a float out
float windChill(float& d, float& w, bool& x) {
float out;
if (x == false) {
out = 35.74 + 0.6215 * cToF(d) - 35.75 * pow(w, 0.16) + 0.4275 * cToF(d) * pow(w, 0.16);
}
else {
out = 35.74 + 0.6215 * d - 35.75 * pow(w, 0.16) + 0.4275 * d * pow(w, 0.16);
}
return out;
}
// Function name output, inputs floats d, w, chill, and boolean x, returns a string containing the complete output
string output(float d, float w, float chill, bool x) {
std::ostringstream ss;
ss.precision(3);
string temp;
if (x == true) {
temp = "fahrenheit";
}
else {
temp = "celsius";
}
return "For " + to_string(d) + " " + temp + " and " + to_string(w) + " mph wind, the windchill is: " + to_string(chill);
}
int main()
{
const int MINF = -80;
const int MAXF = 121;
const int MINC = -62;
const float MAXC = 49.5;
float c = -100;
float f = 200;
float w;
string temp;
bool range = false;
bool tilSpeed = false;
bool isF = false;
cout << "Do you want to enter in Fahrenheit (F) or (C)" << endl;
cin >> temp;
while(range == false) {
if (temp == "C") {
range = true;
cout << "Enter a temperature in Celsius between -62 and 49.5: " << endl;
cin >> c;
if (c < MINC || c > MAXC) {
range = false;
}
else {
cout << "You entered " << c << " degrees celsius, or " << cToF(c) << " degrees fahrenheit" << endl;
tilSpeed = true;
}
}
else if (temp == "F") {
range = true;
cout << "Enter a temperature in Fahrenheit between -80 and 121: " << endl;
cin >> f;
if (f < MINF || f > MAXF) {
range = false;
}
else {
cout << "You entered " << f << " degrees fahrenheit" << endl;
tilSpeed = true;
}
}
else {
cout << "Do you want to enter in Fahrenheit (F) or (C)" << endl;
cin >> temp;
}
if (range == true) {
tilSpeed = true;
cout << "Enter a speed between 0 and 231: " << endl;
cin >> w;
while (w > 231 || w < 0) {
cout << "Enter a speed between 0 and 231: " << endl;
cin >> w;
}
}
}
if (c != -100) {
isF = false;
cout << setprecision(2) << output(c, w, windChill(c, w, isF), isF);
}
else if (f != 200) {
isF = true;
cout << setprecision(2) << output(f, w, windChill(f, w, isF), isF);
}
}
|