summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/cst116-lab2-stark.cpp
blob: ea916108d4f5451d5f22b281ffc7195ffa70091e (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
// Trenton Stark
// CST-116
// Lab 2

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

void inputTemp(float& cTemp, float& fTemp);
float tempConverter(float temp, bool dirc);
void inputWind(float& windS);
float windChillCalc(float windS);

const float fMin = -80, fMax = 121, cMin = -62, cMax = 49.5, wMin = 0, wMax = 231; //Minimum and maximum valid ranges for all user inputs

int main() {
	float cTemp, fTemp, windS;

	cout << "Welcome to Cold Calculator v0.2" << endl;

	inputTemp(cTemp, fTemp);
	inputWind(windS);
	cout << cTemp << endl;
	cout << fTemp << endl;
	cout << windS << endl;
}

//Takes either celcius or fahrenheit then converts it to the other and outputs both by reference
void inputTemp(float& cTemp, float& fTemp) {
	char tempType;

	cout << "Would you like to enter the temperature in Celcius (c) or Fahrenehit (f)?" << endl;
	do {
		cin >> tempType;
		cout << endl;
		if (tempType != 'f' && tempType != 'c') {
			cout << "Input the character 'c' or 'f'!" << endl;
		}
	} while (tempType != 'f' && tempType != 'c');

	if (tempType == 'c') {
		cout << "What is the temperature in Celcius (-62 - 49.5 degrees)?" << endl;
		do {
			cin >> cTemp;
			cout << endl;
			if (cTemp < cMin || cTemp > cMax) {
				cout << "Input a value between -62 and 49.5 degrees!" << endl;
			}
			fTemp = tempConverter(cTemp, 0);
		} while (cTemp < cMin || cTemp > cMax);
	}
	else {
		cout << "What is the temperature in Fahrenheit (-80 - 121 degrees)?" << endl;
		do {
			cin >> fTemp;
			cout << endl;
			if (fTemp < fMin || fTemp > fMax) {
				cout << "Input a value between -80 and 121 degrees!" << endl;
			}
			cTemp = tempConverter(fTemp, 1);
		} while (fTemp < fMin || fTemp > fMax);
	}
}


// Direction is 0 if going celcius to fahrenheit and 1 if going fahrenheit to celcius
float tempConverter(float temp, bool dirc) {
	float cTemp;

	if (dirc == 0) {
		cTemp = (temp * (9.0 / 5.0)) + 32;
	}
	else {
		cTemp = (temp - 32) * (5.0 / 9.0);
	}

	return cTemp;
}

void inputWind(float& windS) {
	cout << "What is the wind speed in miles per hour (0 - 231)" << endl;
	do {
		cin >> windS;
		cout << endl;
		if (windS < 0 || windS > 231) {
			cout << "Input a value between 0 and 231 miles per hour!" << endl;
		}
	} while (windS < 0 || windS > 231);
}

float windChillCalc(float windS) {

}