#include <iostream>
usingnamespace 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.
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;
#include <iostream>
usingnamespace 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.