Weather statistics using structure

I have been working on this for awhile, but I was hoping to get input from someone with more experience.
I have to stick with the structure and enum format for the assignment, but I was wondering if anyone had any opinions on the way the high/low temperature sections should be done?
Thanks for your help, I appreciate any hints.

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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct WeatherInfo
{
    double rainfall;
    double highTemp;
    double lowTemp;
 };
    
enum Month {January, February, March, April,
                May, June, July, August,
                September, October, November, December};
                             

int main()
 {
    const int MONTHS = 3;
    WeatherInfo month[MONTHS];
    int index;
    
    double rainTotal = 0.0;
    double tempTotal = 0.0;
    double tempHigh = 0.0;
    double tempLow = 0.0;

    for (index = January; index <= March; index = static_cast<Month>(index +1))
     { 
		cout << "Please enter the rainfall in inches";
		cout << (index + 1) << " :";
		cin >> month[index].rainfall;
		rainTotal += month[index].rainfall;
		
		cout << "Please enter the temperature";
		cout << (index + 1) << " :";
		cin >> tempTotal;
            
            if ( tempTotal < -100 || tempTotal > 140) 
            { 
                cout << "The temperature you entered is invalid" << endl; 
                cout << "Please re-enter: "; 
                cin >> tempTotal; 
            } 
            
            if (month[index] > tempTotal)
		{
			tempHigh += month[index].highTemp;
		}
		
		 if (month[index] < tempTotal)
		{
			tempLow += month[index].lowTemp;
		}
		
    }

    cout << "The total rainfall for the year is " << rainTotal << endl; 
	cout << "The highest temperature is " << tempHigh << endl;
	cout << "The lowest temperature is " << tempLow << endl;
	    
return 0;

}
I dont quite get it, and it looks like you too are undecided:
What WeatherInfo object represents?
If you need statistics for 3 months, do you create one WeatherInfo for each month, or there is just one WeatherInfo for entire period? Because you measure rainfall independently in each of 3 WeatherInfo's . That would mean you need also provide coldest and warmest temperature for each of three months, correct?
Or maybe each month can only have one temperature?
1
2
3
4
5
WeatherInfo
{
    double rainfall;
    double temp;
}


And then the function should only calculate average of the 3, compare them to one another and find min and max values?

Last edited on
Topic archived. No new replies allowed.