summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: eb113441a29ad76eefbf9259e27ba7f1b60a1585 (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
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

using namespace std;

const float MINFTEMP = -80;
const float MAXFTEMP = 121;

const float MINCTEMP = -62;
const float MAXCTEMP = 49.5;

const float MINWSPEED = 0;
const float MAXWSPEED = 231;


const string YES_WORD = "yes";

void convertValueToFarenheit(float& celsiusvalue);
float calculateWindChill(float temp, float wind_speed);
void outputData(float temp, float wind_speed, float wind_chill);

int main()
{
	float temp = -81;
	float wind_speed = -1;


	bool ferenheit = true;
	string input_word;

	cout << "Will you be inputting your data in celcius? If yes, then please type 'yes':    ";
	cin >> input_word;
	cout << endl;
	cin.clear();
	if (input_word == YES_WORD)
	{
		ferenheit = false;
	}

	while (
		(ferenheit && ((MINFTEMP > temp) || (MAXFTEMP < temp))) ||
		(!ferenheit && ((MINCTEMP > temp) || (MAXCTEMP < temp)))
		)
	{
		if (ferenheit)
		{
			cout << "Please input a temperature in Ferenheit, it must not be less than " << MINFTEMP << "F or greater than " << MAXFTEMP << "F.:    ";
		}
		else {
			cout << "Please input a temperature in Celcius, it must not be less than " << MINCTEMP << "C or greater than " << MAXCTEMP << "C.:    ";
		}

		cin >> temp;
		cout << endl;
		cin.clear();
	}

	if (!ferenheit) convertValueToFarenheit(temp);
	

	while ((MINWSPEED > wind_speed) || MAXWSPEED < wind_speed)
	{
		cout << "Please input a wind speed in Miles per Hour, it must not be less than " << MINWSPEED << "m/p or greater than " << MAXWSPEED << "m/p.:    ";
		cin >> wind_speed;
		cout << endl;
		cin.clear();
	}


	outputData(temp, wind_speed, calculateWindChill(temp, wind_speed));

	return 0;
}

/// <summary>
/// Edits the reference 'celsiusvalus' to conver it to Ferenheit;
/// </summary>
/// <param name="celsiusvalue"></param>
void convertValueToFarenheit(float& celsiusvalue)
{
	celsiusvalue * (9.0 / 5.0);
	celsiusvalue += 32;
}
/// <summary>
/// Calculates the wind chill and returns that from temp and wind_speed;
/// </summary>
/// <param name="temp"></param>
/// <param name="wind_speed"></param>
/// <returns></returns>
float calculateWindChill(float temp, float wind_speed)
{
	return 35.74 + .6215 * temp - 35.75 * powf(wind_speed, 0.16) + .4275 * temp * powf(wind_speed, 0.16);
}
/// <summary>
/// Outputs the three inputs to the console with formatting;
/// </summary>
/// <param name="temp"></param>
/// <param name="wind_speed"></param>
/// <param name="wind_chill"></param>
void outputData(float temp, float wind_speed, float wind_chill)
{
	cout << "Temperature: " << temp << "F" <<
		"\n Wind Speed: " << wind_speed << "m/p" <<
		"\n Wind chill: " << wind_chill << endl;
}