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
|
// 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);
// function main, no inputs, returns 0
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;
}
// function selectType, no inputs, returns select
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;
}
// function getTemp, inputs select, returns temp
float getTemp(int& select)
{
float temp =-100;
const int minC = -62;
const int maxC = 49.5;
const int minF = -80;
const int maxF = 121;
if (select == 1)
{
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;
}
}
if (select == 2)
{
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;
}
}
return temp;
}
// function calcTemp, nputs temp, returns temp
float calcTemp(float& Celsius)
{
float Fahrenheit = 0;
Fahrenheit = 32 + ((9 * Celsius) / 5);
return Fahrenheit;
}
// function getWindSpeed, no inputs, returns windSpeed
float getWindSpeed()
{
float windSpeed = -100;
{
while (windSpeed < 0 || windSpeed > 231)
{
cout << endl << "Enter wind speed in MPH: ";
cin >> windSpeed;
if (windSpeed < 0 || windSpeed > 231)
cout << endl << "Please enter between " << 0 << " and " << 231 << "." << endl;
}
}
return windSpeed;
}
// function getWindChill, inputs temp and windSpeed, no return
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;
}
|