Your program got many errors
I listed that I remembered
1. u cannot initialize an array size through user input
2. struct shall declared outside the main and also before function proto type.
3. in the function definition average_age, you didnt pass the struct student array as a parameter to the function.
4. the
average_age function didnt return any value.
5. you declared
average_age and
total_age in the main but u didnt initialize it. it has to be initialize to '
0' or some other value, because your passing it as paramter to the function. where you calculating the value for those. And you have to pass it as reference parameters to the function not as value parameters.
6. and the main has to be
int main
After correcting all those errors, your code is
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
|
#include<iostream>
#include<conio.h>
using namespace std;
struct student
{
char name[40];
char course[50];
int age;
float GPA;
};
float average_age(student stu[],int);
float average_gpa(int,float);
float max_gpa(float);
int main()
{
const int no_of_students=2;
//int no_of_students;//no of students u want tO caLcuLate
//cout<<"pLz enter the nO of students : ";//prOmpt tO user
//cin>>no_of_students;//u cannot assign array size by user declaration
student students[no_of_students];//array of data type student
//Loop run tO populate the structure student attribute by user
for(int i=0;i<no_of_students;i++)
{
cout<<endl<<"enter dAta fOr student."<<i+1<<endl;
cout<<"enter studenT's nAme : ";
cin>>students[i].name;
cout<<"enter studenT's cOurse : ";
cin>>students[i].course;
cout<<"enter studenT's agE : ";
cin>>students[i].age;
cout<<"enter studenT's gpA : ";
cin>>students[i].GPA;
}
cout<<"the average agE iz : "<<average_age(students,no_of_students)<<endl;
//cout<<"the average gPA iz : "<<average_gpa(total_gpa,avr_gpa)<<endl;
//cout<<"the maximum gpA iz : "<<max_gpa(maxgpa)<<endl;
system("pause");
}
float average_age(student stu[],int NO_OF_STUDENTS)//avr_age mnz average age
{
float total_age=0;
float avr_age;
for(int i=0;i<NO_OF_STUDENTS;i++)
{
total_age += stu[i].age;
avr_age=total_age/NO_OF_STUDENTS;
}
return avr_age;
}
|
Compare it with your code and you know the errors
I removed some things as they are not neccessary