blob: bb45c0ac5cc0db82142758c48ce860daf4888701 (
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
115
116
117
118
119
120
121
122
123
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath> //need this to use the pow math
using namespace std;
using std::cout;
using std::cin;
using std::endl;
float far;
float cel;
float mph;
float newFar;
float chill;
//The following const are for the while loops to control what user can enter
const int celmin = -62;
const float celmax = 49.5;
const int farmin = -80;
const int farmax = 121;
const int mphmin = 0;
const int mphmax = 231;
//to check for user to enter celcius or fahrenheit
string check;
const string celcheck = "c";
float celtofar(float cel);
float getParam(float& far, float& mph);
float windchill(float far, float mph);
float getMPH(float& mph);
int main() // calls functions and then displays the fahrenheit and windchill at the end
{
far = 0.0;
cel = 0.0;
mph = 0.0;
cout << "Do you want to enter fahrenheit or celcius? Enter f or c" << endl;
cin >> check;
if (check == celcheck)
{
celtofar(cel);
far = newFar;
getMPH(mph);
}
else
getParam(far, mph);
windchill(far, mph);
cout << "You entered " << far << "F" << endl;
cout << "For " << far << " degrees F and " << mph << " MPH wind speed, the windchill is: " << chill;
return 0;
}
float getParam(float& far, float& mph) //gets fahrenheit and wind speed from user
{
cout << "Please enter your fahrenheit temp:" << endl;
cout << "Must be between " << farmin << " and " << farmax << endl;
cin >> far;
while (far < farmin || far > farmax)
{
cout << "Please enter your fahrenheit temp:" << endl;
cout << "Must be between " << farmin << " and " << farmax << endl;
cin >> far;
}
cout << "Please enter your wind speed in mph:" << endl;
cout << "Must be between " << mphmin << " and " << mphmax << endl;
cin >> mph;
while (mph < mphmin || mph > mphmax)
{
cout << "Please enter your wind speed in mph:" << endl;
cout << "Must be between " << mphmin << " and " << mphmax << endl;
cin >> mph;
}
return far, mph;
}
float celtofar(float cel) //calculates celcius to fahrenheit and returns the value
{
cout << "Please enter your celcius temp:" << endl;
cout << "Must be between " << celmin << " and " << celmax << endl;
cin >> cel;
while (cel < celmin || cel > celmax)
{
cout << "Please enter your celcius temp:" << endl;
cout << "Must be between " << celmin << " and " << celmax << endl;
cin >> cel;
}
newFar = (9 / 5) * cel + 32;
return newFar;
}
float windchill(float far, float mph) //calculates wind chill and returns it
{
chill = 35.74 + (.6215 * far) - (35.75 * pow(mph, .16)) + (.4275 * pow(far, .16));
return chill;
}
float getMPH(float& mph) //gets mph only for when you select celcius function
{
cout << "Please enter your wind speed in mph:" << endl;
cout << "Must be between " << mphmin << " and " << mphmax << endl;
cin >> mph;
while (mph < mphmin || mph > mphmax)
{
cout << "Please enter your wind speed in mph:" << endl;
cout << "Must be between " << mphmin << " and " << mphmax << endl;
cin >> mph;
}
return mph;
}
|