Can't solve a struct init-declarator error

Hi guys, check out my program, I am desperately in the need of help because I can't fix my error.
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
#include <iostream>
using namespace std;
int main()
struct stud
{
{
       char name[30];
       char fNumber[12];
       char course[20];
       float marks;
};
stud student[50], counter;
int n;
int i;
cout<<"Input the number of students n<=50 ";
cin>>n;
{
       cout<<"Input a name : ";
       cin>>student[i].name;
       cout<"Input the faculty number : ";
       cin>>student[i].fNumber;
       cout<<"Input the student's course : ";
       cin>>student[i].course;
       cout<<"Input the student's marks : ";
       cin>>student[i].marks;
};
for(i=0;i<n;i++)
if(student[i].marks=>5.50)
{
                         cout<<"Name: "<<student[i].name<<endl;
                         cout<<"fNumber: "<<student[i].fNumber<<endl;
                         cout<<"Student's course: "<<student[i].course<<endl;
                         cout<<"Student's marks: "<<student[i].marks<<endl<<endl;
                         counter++;
}
system("pause")
return 0;
}


4 C:balalalalla expected init-declarator before "struct"
4 C:balalalalla expected `,' or `;' before "struct"

Well that's actually all the information I can give you guys .. I just can't understand the error.Everything seems fine to me, however, it obviously isn't.
Last edited on
I'd advise changing the start to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
struct stud
{
  char name[3];
  char fNumber[12];
  char course[20];
  float marks;
};

int main()
{
stud student[50], counter;
int n, i;
//e.t.c. 

See if that works. Also, you have to put the for statement before the curly braces, not after (later in the program).

If you were to indent your code your might see the various problems you had. You declare a struct then use an opening brace followed by the struct members and a closing brace and semi-colon. Likewise for a for loop, you have an opening brace followed by body of the for loop and a closing brace. The student[i].marks float uses a >= operator not =>. counter is a stud struct variable and the stud struct does not have a ++ operator. You need to end the line 36 with a semi-colon;

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

int main()
{
   struct stud
   {
       char name[30];
       char fNumber[12];
       char course[20];
       float marks;
   };

   stud student[50], counter;
   int n;
   int i;
   cout<<"Input the number of students n<=50 ";
   cin>>n;
   cout<<"Input a name : ";
   cin>>student[i].name;
   cout<"Input the faculty number : ";
   cin>>student[i].fNumber;
   cout<<"Input the student's course : ";
   cin>>student[i].course;
   cout<<"Input the student's marks : ";
   cin>>student[i].marks;

   for(i=0;i<n;i++)
   {
	if(student[i].marks >= 5.50)
	{
		cout<<"Name: "<<student[i].name<<endl;
		cout<<"fNumber: "<<student[i].fNumber<<endl;
		cout<<"Student's course: "<<student[i].course<<endl;
		cout<<"Student's marks: "<<student[i].marks<<endl<<endl;
//		counter++;	struct 'stud' does not have ++ operator
	}
   }

   system("pause");
   return 0;
}
Last edited on
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
#include <iostream>
using namespace std;
struct stud
{
  char name[30];
  char fNumber[12];
  char course[20];
  float marks;
};
int main()
{
stud student[50];
int n, i;
cout<<"Input the number of students n<=50 : ";
cin>>n;
for(i=0;i<n;i++)
{       
       cout<<"Input the student's name : ";
       cin>>student[i].name;
       cout<<"Input the student's faculty number : ";
       cin>>student[i].fNumber;
       cout<<"Input the student's course : ";
       cin>>student[i].course;
       cout<<"Input the student's marks : ";
       cin>>student[i].marks;
       cout<<"____________________________________"<<endl;
};
int counter=0;
for(i=0;i<n;i++)
if(student[i].marks>=5.50)
{
                         cout<<"The students who have marks above 5.50 are : "<<endl;
                         cout<<student[i].name<<endl;
                         cout<<"Student's faculty number : "<<student[i].fNumber<<endl;
                         cout<<"Student's course : "<<student[i].course<<endl;
                         cout<<"Student's marks : "<<student[i].marks<<endl<<endl;
                         ++counter;                         
}
cout<<"The number of students with marks above 5.50 are : ";
cout<<counter<<endl;
system("pause");
return 0;
}


That's what I have come up to.Generally, it's working and all except for one mistake I am yet to fix : cout<<"The students who have marks above 5.50 are : "<<endl;
This gets displayed for every student and I want it to get displayed on the top of all students with marks above 5.50 only once .. would be thankful if anyone gave a tip.Tried putting it before the { below the if, I get random egyptian symbols.
Put it before line 29.
Or put an opening curly brace after line 29 and a closing one after line 38.
My gawd, why haven't I thought of putting it before line 29 ehuauheahueahuueha I'm so freakin' retarded.Thank you for all the advices guys.
Topic archived. No new replies allowed.