Step Through an Array Elements. Help!

OKay I have this weather program I finished. But now I have to modify the program so it defines an enumerated data type with enumerators for the months January and etc. The program should use the enumerated type to step through the elements of the array.

I keep getting this error.
a Vaule of type "Month" cannot be assigned to an entity of type "Month"
Error starts at rainMonth =

What am i doing wrong? How do i finish the code?

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

struct weather
{
	double rainfall;
	double high_temp;
	double low_temp;
	double avg_temp;
}
;
enum Month { January, Februaury, March, April, May,
		         June, July, August, September, October, November
				 , December};
int main()
{

	const int NUM_MONTHS = 12; // Number of months
	weather months[NUM_MONTHS];
	int i;
	double yearlyRain = 0.0, avgRain;
	enum Month { Janurauy, Februaury, March, April, May,
		         June, July, August, September, October, November
				 , December};
	Month rainMonth;

	for (rainMonth = January; rainMonth <= December;
		                      rainMonth = static_cast<Month>(rainMonth +1))
		/*int i = 0; i < NUM_MONTHS; i++)*/
	{

		cout << "Please enter the rainfall inches of month ";
		cout << (i + 1) << " :";
		cin >> months[i].rainfall;
		yearlyRain += months[i].rainfall;
		avgRain = yearlyRain/12;
		
	}

	cout << "The total rainfall for the year is: "
	     << yearlyRain << " inches" << endl;

	//Avg rain for the year
	cout << "The average rainfall fpr the year is ";
	cout << yearlyRain << " inches" << endl;

	_getch();
}
You have
enum Month {/* ... */};
declared twice.
(once outside of main(), and one inside it)

Remove one of them and you should be fine.
Topic archived. No new replies allowed.