blob: 9db8518a5fe8c7f412178aa1bd202ff8c9f908b8 (
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
|
// CST 116, Lab2: Baby it's cold outside, Lloyd Crawford. This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
//Part 2
float c_2_f(float c)
{
return (9.0 / 5.0) * (c + 32);
}
void f_2_c(float f, float& c)
{
c = (5.0 / 9.0) * (f - 32);
}
float GetWindChill(float temp, float windSpeed)
{
// Calculates the wind chill in fahrenheit, and can convert it to celsius using a previous function
float windChill;
windChill = 35.74 + (0.6215 * temp) + (pow(windSpeed, 0.16) * ((0.4275 * temp) - 35.75));
return windChill; // Returns the wind chill based on what the user entered before the function has been called. Only outputs as fahrenheit.
}
int main()
{
//Part 1
char convert_choice = '0';
float celcius = -200; // force to be out of range -62 to 49.5
float fahrenheit = -200; // force to be out of range -80 & 121
float windChill = 0;
float windSpeed = -1; // force to be out of range 0 and 231
while (convert_choice != 'C' && convert_choice != 'F') // force to be C or F
{
cout << "Enter C for Celsius to Fahrenheit or F for Fahrenheit to Celsius: ";
cin >> convert_choice;
}
if (convert_choice == 'C')
{
while (celcius < -62 || celcius > 49.5) // force range here -62 to 49.5
{
cout << "Enter a number for degree in Celsius from -62 to 49.5: ";
cin >> celcius;
}
fahrenheit = c_2_f(celcius);
}
else
{
while (fahrenheit < -80 || fahrenheit > 121) // forces fahrenheit to be between -80 & 121
{
cout << "Enter a number for degree in fahrenheit from -80 to 121: ";
cin >> fahrenheit;
}
f_2_c(fahrenheit, celcius); // call conversion function with pbv and pbr parameters
}
while (windSpeed < 0 || windSpeed > 231) {
cout << "Please enter a number for the wind speed from 0 to 231 mph.\n";
cin >> windSpeed;
}
windChill = GetWindChill(fahrenheit, windSpeed);
cout << fixed << setprecision(2) << left;
cout << setw(20) << "CELSIUS" << setw(20) << "FAHRENHEIT" << setw(20) << "WIND SPEED" << setw(20) << "WIND CHILL" << endl;
cout << setw(20) << celcius << setw(20) << fahrenheit << setw(20) << windSpeed << setw(20) << windChill << endl;
cout << "Here is your data. Bundle up!" << endl;
return 0;
}
|