blob: f9f39e2b147723fda6879fc2a1f241376476aa5c (
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
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
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
// Name: Taylor Rogers
// Assignment: Lab 2
//
#include <iostream>
#include <math.h>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
const int Fmax = 121;
int Fmin = -80;
const int Cmax = 49.5;
int Cmin = -62;
const int Wmax = 231;
const int Wmin = 0;
char Tunit{};
float TvalF{};
float TvalC{};
int Wspeed{};
float Wchill{};
// Converts Fahrenheit to Celsius
float FtoCfunc(float FtoCval)
{
FtoCval = 0;
FtoCval = (TvalF - 32) * (5.0f / 9.0f);
TvalC = FtoCval;
return TvalC;
}
// Converts Celsius to Fahrenheit
float CtoFfunc(float CtoFval)
{
CtoFval = 0;
CtoFval = (9.0f / 5.0f) * TvalC + 32;
TvalF = CtoFval;
return TvalF;
}
// Converts Windspeed and Temp to Winchill
float Wchfunc(float& Wchcalc)
{
Wchcalc = 0;
Wchcalc = 35.74f + .6215f * TvalF - 35.75f * (pow(Wspeed, 0.16f)) + 0.4275f * TvalF * (pow(Wspeed, 0.16f));
Wchill = Wchcalc;
return Wchill;
}
int main()
{
char continu = 'Y';
while (continu == 'Y')
{
// Temp unit selection
cout << "Please enter F for Fahrenheit or C for Celsius: ";
cin >> Tunit;
cout << endl;
// Temp input in F
if (Tunit == 70 || Tunit == 102)
{
cout << "Please enter temperature between " << Fmin << " and " << Fmax << " degrees F: ";
cin >> TvalF;
cout << endl;
while (TvalF < Fmin || TvalF > Fmax)
{
cout << "Please enter a value between " << Fmin << " and " << Fmax << ": ";
cin >> TvalF;
}
FtoCfunc(TvalC);
}
// Temp input in C
else if (Tunit == 67 || Tunit == 99)
{
cout << "Please enter temperature between " << Cmin << " and " << Cmax << " degrees C: ";
cin >> TvalC;
cout << endl;
while (TvalC < Cmin || TvalC > Cmax)
{
cout << "Please enter a value between " << Cmin << " and " << Cmax << ": ";
cin >> TvalC;
}
CtoFfunc(TvalF);
}
else
{
cout << "Invalid unit" << endl;
return 0;
}
//Windspeed
cout << "Please enter a windpeed value between 0 and 231 in Miles Per Hour: ";
cin >> Wspeed;
cout << endl;
while (Wspeed < Wmin || Wspeed > Wmax)
{
cout << "Please enter a value between " << Wmin << " and " << Wmax << ": ";
cin >> Wspeed;
}
Wchfunc(Wchill);
cout << endl;
cout << setw(25) << "Temp (C)" << setw(25) << "Temp (F)" << setw(25) << "Wind Speed (MPH)" << setw(25) << "Wind Chill" << endl;
cout << setw(25) << TvalC << setw(25) << TvalF << setw(25) << Wspeed << setw(25) << Wchill << endl;
cout << endl;
cout << "Want to do again? Type \'Y\': ";
cin >> continu;
}
}
|