Help with finding higest and lowest

How can I properly find the lowest and the highest temperatuers?

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
#include <iostream>
#include <string>
using namespace std;



struct months
{
	float rain;
	float high;
	float low;
	float average;
};


int main()
{
	const int month= 12;
	months total[month];
	float totalRain=0;
	int highest = 0;
	int lowest = 0;

	string monthName[month]={"January","February","March","April","May","June","July","August",
 "September","October","November","December"};

	for(int i=0; i<12; i++){;
		cout << monthName[i] << endl;
		cout << endl;
		cout << "Enter total rain for this month: ";
		cin >> total[i].rain;
		cout << endl;
		cout << "Enter the highest temperature for this month: ";
		cin >> total[i].high;
		while(total[i].high<-100||total[i].high>140)
	{
		cout << endl;
		cout<<"Invalid entry-must be between -100 through 140\n";
		cout<<"high temperature: ";
		cin>>total[i].high;
		cout << endl;
 }
		cout << endl;
		cout << "Enter the lowest temperature for this month: ";
		cin >> total[i].low;
		while(total[i].low<-100||total[i].low>140)
 {
	 cout << endl;
	 cout<<"Invalid entry-must be between -100 through 140\n";
	 cout<<"high temperature: ";
	 cin>>total[i].low;
	 cout << endl;
 }
		cout << endl;
		cout << endl;
		total[i].average = (total[i].high+total[i].low)/2;
		cout <<"The avearge temperature of this month is: " << total[i].average;
		cout << endl;
		cout << endl;
		
		totalRain+=total[i].rain;
		if(total[i].high>total[highest].high)
		{
			i=highest;
		}
		if(total[i].low >total[lowest].low)
		{ 
			i=lowest;
	}
}
	cout << endl;
		cout << "The total rainfall for the year was: " << totalRain << endl;
		cout << highest << endl;
		cout << lowest;

	system("PAUSE");
	return 0;
}
Last edited on
float lowestTemp = 140;
string = lowestMonth;

for(int i=0; i<12; i++){;

if (lowestTemp > total[i].low);
lowestTemp = total[i].low;
lowestMonth = monthName[i];
}

You'll probably have to clean that up alot to get it to work, but I think thats the basic logic of it. Let me know how it works out for you.
Topic archived. No new replies allowed.