summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: e6b96c76bb48adc106250d9adaf2f10242a6c0e9 (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
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
/*
Thomas Trinh
CST116
Lab2: Calculate the wind chill given a temperature and wind speed
*/

#include <iostream>
#include <iomanip>
using namespace std;

const float MinF = -80;
const float MaxF = 121;
const float MinC = -62;
const float MaxC = 49.5;
const float MinW = 0;
const float MaxW = 231;
const string word = "yes";
void convertCelsiustoFahrenheit(float& celciusvalue);
float WindChillcalc(float temp, float wspeed);
void outputdata(float temp, float wspeed, float wchill);

int main()
{
	float temp = 122;
	float wspeed = 232;

	bool fahrenheit = true;
	string input;

	cout << "Are you entering temperature in celsius? Say yes if yes, no or anything else if no: ";
	cin >> input;
	cout << endl;

	if (input == word)
	{
		fahrenheit = false;
	}

	while (fahrenheit && ((MinF > temp) || (MaxF < temp)) || (!fahrenheit && ((MinC > temp) || (MaxC < temp))))
	{
		if (fahrenheit)
		{
			cout << "Input a fahrenheit temperature that is greater than " << MinF << " but less than " << MaxF << ": ";
		}
		else {
			cout << "Input a celsius temperature that is greater than " << MinC << " but less than " << MaxC << ": ";
		}

		cin >> temp;
		cout << endl;

	}
	if (!fahrenheit) convertCelsiustoFahrenheit(temp);

	while ((MinW > wspeed) || (MaxW < wspeed))
	{
		cout << "Input a wind speed in that is greater than " << MinW << " but less than " << MaxW << ": ";
		cin >> wspeed;
		cout << endl;
	}

	outputdata(temp, wspeed, WindChillcalc(temp, wspeed));

	return 0;
}
/// <summary>
/// Changes the reference celciusvalue to fahrenheit
/// </summary>
/// <param name="celciusvalue"></param>
void convertCelsiustoFahrenheit(float& celciusvalue)
{
	celciusvalue * (9.0 / 5.0);
	celciusvalue + 32;
}
/// <summary>
/// Calculates the wind chill and returns it from the temperature and wind speed
/// </summary>
/// <param name="temp"></param>
/// <param name="wspeed"></param>
/// <returns></returns>
float WindChillcalc(float temp, float wspeed)
{
	return 35.74 + 0.6215 * temp - 35.75 * powf(wspeed, 0.16) + 0.4275 * temp * powf(wspeed, 0.16);
}
/// <summary>
/// Outputs the 3 inputs with format
/// </summary>
/// <param name="temp"></param>
/// <param name="wspeed"></param>
/// <param name="wchill"></param>
void outputdata(float temp, float wspeed, float wchill)
{
	cout << "Temperature: " << temp << "F" << endl;
	cout << "Wind speed: " << wspeed << "mph" << endl;
	cout << "Wind chill: " << wchill << endl;
}