Fixing compiler error C2228 left of " " must have class/struct/union

Hey guys I have my code all written but keep getting the error message "error C2228 left of " " must have class/struct/union. This is the only error message I am getting when I compile my project but I don't know how to fix it at all. If someone can help me out, that'd be great.

The errors are on the lines mentioned below so you don't have to look
- 66
- 74
- 83
- 87
- 88
- 100
- 102
- 103
- 114
- 116

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;

const int MAX_ID = 3345;			// Maximum siteIDNumber
const int MAX_WINDSPEED = 22;		// Maximum windSpeed
const int MAX_DAY = 16;				// Maximum dayOfMonth
const int MAX_TEMP = 30;			// Maximum temperature
const int MAX = 10;					// Max array size

struct measured_data_t
{
	int siteIDNumber, dayOfMonth, 
		windSpeed, temperature;
};

int main()
{
	measured_data_t data[MAX];
	char temp[10];
	measured_data_t a_measured_data;
	int i,n,var;
	int max[3]={0,0,0},min[3],diff[3],avg[3]={0,0,0},count[3]={0,0,0};
	n = 0;
	cout << " Weather and Climate Research Data " << endl; 
	cout << " Temp variation & average wind speed " << endl; 
	
	FILE *infilep; /* file pointer */
	infilep = fopen(" C:\Users\David\Desktop\data.txt ", "r"); /* open file in read mode */

	if (infilep == NULL)
		{
			cout << " Cannot Open File - Check File Name " << endl;
		}

	for (i=0;i<8;i++) /* To just skip the first line */
	{
		fscanf(infilep,"%s",&temp);
	}
		for ( i=0; i; )
		{
			fscanf(infilep, "%4d %3d %3d %3d",&a_measured_data.siteIDNumber,&a_measured_data.dayOfMonth,&a_measured_data.windSpeed,&a_measured_data.temperature);
			data[n]=a_measured_data;
			n++;
		}
	fclose(infilep);

cout << " site ID, Day of Month, Wind speed, Temp " << endl;
	
	for( i=0; i; )
	{
		cout << " %4d %3d %3d %3d " << endl;
	}

	cout << " \n\n " << endl;

/* To get the different ID Values */

	n=0;
	diff[0]=data[0].siteIDNumber;
	for ( i=0; i; )
	{
	        if (diff[n]==data.siteIDNumber)
	{
	
		continue;
	}
	else
	{
		n++;
		diff[n]=data.siteIDNumber;
	}
	}

/* To get the Maximum value of temperature for all individual ID */

	n=0;
	for( i=0; i; )
	{
		if (diff[n]==data.siteIDNumber)
		{
			if(max[n])
			{
				max[n]=data.temperature;
				min[n]=data.temperature; //We are setting min value of temperature to maximum value so that it can further be decreased
			}
			n++;
		}
	}

/* To get the Minimum value of temperature for all individual ID */

	for( i=0; i; )
	{
		for(n=0;n<3;n++)
		{
			if(diff[n]==data.siteIDNumber)
			{
				if(min[n]>data.temperature)
				min[n]=data.temperature;
			}
		}
	}

/* to Get the Average windfall for the given ID */

	for( i=0; i; )
	{
		for(n=0;n<3;n++)
		{
			if(diff[n]==data.siteIDNumber)
			{
				avg[n]=avg[n]+data.wind_speed;
				count[n]+=1;
				continue;
			}
		}
	}

/* Display Calculated data */

	cout << " site ID, Max Temp, Min Temp, Variation, Mean Wind speed " << endl;
	for(i=0;i<3;i++)
	cout << " %d\t%d\t%d\t%d\t%d\n " << diff << max << min << max-min << avg << endl;

/* To calculate the value of greatest variation in temperature*/

	var=0;
	for(n=0;n<3;n++)
	{
		if((max[n]-min[n])>var)
		var=max[n]-min[n];
	}

/* Print Greatest Variation in temperature*/

	cout << " Temperature " << endl;
	for(n=0;n<3;n++)
	{
		if((max[n]-min[n])==var)
		cout << " Greatest Variation is at Site Id " << diff[n] << endl;
	}

/* To calculate the value of greatest variation for average wind speed*/

	var=0;
	for(n=0;n<3;n++)
	{
		if((avg[n]/count[n])>var)
		var=avg[n]/count[n];
	}

/* Print Greatest variation in average wind speed */

	cout << " Average Wind Speed " << endl;
	for(n=0;n<3;n++)
	{
		if((avg[n]/count[n])==var)
		cout << " Greatest Variation is at Site ID " << diff[n] << endl;
	}
}
Last edited on
Next time report the number of the erroneous statement.

I do not see a closing parenthesis in the if statement

1
2
3
4
5
6
7
	for ( i=0; i; )
	{
	        if (diff[n]==data.siteIDNumber
	{
	
		continue;
	}
Last edited on
okay thanks i fixed that and I also added the lines that the errors are on.
closed account (Dy7SLyTq)
it would make it easier to just post the whole log..

-line 66: you used diff before giving it any values
same with next two errors. for line 87 im going to assume you didnt give data.temperature a value, especially since you have an error on 88. 100 you still havent given diff a value before using. 102-3 data.tempature still needs a value before using it. 114 you use diff again without giving it a value. data is used without giving it a value
Okay I see what you are saying but am still confused. I don't understand what you mean by saying that I need to give diff and data.temperature a value. Can you show me what you mean by this?
line 66:
 
if (diff[n]==data.siteIDNumber)


data is an array. You need to specify the index. Did you mean:

if (diff[n]==data[i].siteIDNumber) or

if (diff[n]==data[n].siteIDNumber) ?

You do the same thing on the other lines. I just picked up on the syntax error. I didn't read the code to see what you are actually doing.

Also in your for loops for( i=0; i; ) you never use i. The way they are written they will never execute since i = 0; at the start of the loop and the condition for the loop is also i; which evaluates to false. I'm not sure what you are doing there.
Got the errors to disappear, thanks Alrededor!
Topic archived. No new replies allowed.