aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/temperature.hpp
blob: 38e5d4f9a97f4f67d84b4c8156b4d5d9ef6fe25c (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
#ifndef TEMPERATURE_H
#define TEMPERATURE_H

#include <iostream>

#include "clear.hpp"

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


struct temp
{
	float high;
	float low;

};

inline void Day(int num)
{
	switch (num)
	{
	case 1:
		cout << "Sunday";
		break;
	case 2:
		cout << "Monday";
		break;
	case 3:
		cout << "Tuesday";
		break;
	case 4:
		cout << "Wednesday";
		break;
	case 5:
		cout << "Thursday";
		break;
	case 6:
		cout << "Friday";
		break;
	case 7:
		cout << "Saturday";
		break;
	default:
		cout << "Error";
		
	}
}

inline void Populate(temp temperature[], int size)
{


	for (int i = 1; i < size; i++)
	{

		cout << "\nWhat is the high temp for ";
		Day(i);
		cout << "?: ";
		cin >> temperature[i].high;

		cout << "\nWhat is the low temp for ";
		Day(i);
		cout << "?: ";
		cin >> temperature[i].low;
	}

}

inline void AvgHiLo(const temp temperature[], const int size, float &averageHigh, float &averageLow, float &high, float &low, float &diff)
{
	float placeholder;
	float count = 0;
	high = temperature[1].high;
	low = temperature[1].low;

	for (int i = 1; i < size; i++)
	{
		placeholder = temperature[i].high - temperature[i].low;

		if (diff < placeholder)
			diff = placeholder;
		if (high < temperature[i].high)
			high = temperature[i].high;
		if (low > temperature[i].low)
			low = temperature[i].low;

		averageHigh = averageHigh + temperature[i].high;
		averageLow = averageLow + temperature[i].low;

		count++;
	}

	averageHigh = averageHigh / count;
	averageLow = averageLow / count;
}

inline bool MoreTemps()
{
	char again;

	cout << "\nWould you like to log more temperatures? (Y/N): ";
	cin >> again;

	if (again == 'Y')
		return true;
	else
		return false;
}

inline void StoreTemp()
{
	const int size = 8;

	temp temperature[size];

	float avgHi = 0;
	float avgLo = 0;
	float highest = 0;
	float lowest = 0;
	float diff = 0;

	ClearScreen();

	cout << "*************************************************************\n";
	cout << "Welcome to the temperature logger!\nYou will be prompted to enter the high and low temp for each day of the week.\n";

	Populate(temperature, size);
	AvgHiLo(temperature, size, avgHi, avgLo, highest, lowest, diff);

	ClearScreen();

	cout << "The highest temp was:\n" << highest;
	cout << "\nThe lowest temp was:\n" << lowest;
	cout << "\nThe average high temp was:\n" << avgHi;
	cout << "\nThe average low temp was:\n" << avgLo;
	cout << "\nThe greatest difference in temp was:\n" << diff;

	if (MoreTemps() == true)
		StoreTemp();

}


#endif