#include<iostream>
#include<conio.h>
usingnamespace std;
float average_age(int,float);
float average_gpa(int,float);
float max_gpa(float);
main()
{
int total_age;
float avrage;
struct student //structure student declared
{ //attributes/datatypes of struct students
char name[40];
char course[50];
int age;
float GPA;
};
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;//input by user fOr caLcuLating nO of students
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(total_age,avr_age)<<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(int total_age,float avr_age)//avr_age mnz average age
{
total_age=0;
for(int i=0;i<no_of_students;i++)
{
total_age += students[i].age;
avrage=total_age/no_of_students;
}
}
float average_gpa(int total_gpa,float avr_gpa)//avr_gpa mnz average gpa
{
for(int i=0;i<no_of_students;i++)
{
total_gpa=0;
total_gpa += students[i].GPA;
average_gpa=total_gpa/no_of_students;
}
}
float max_gpa(float maxgpa)
{
maxgpa=0;
for(int i=0;i<no_of_students;i++)
{
if(students[i].GPA>maxgpa)
{
maxgpa=students[i].GPA;
index=i;
}
}
}
cout<<"the average agE iz : "<<average_age(total_age,avr_age)<<endl;
cout<<"the average gPA iz : "<<average_gpa(total_gpa,avr_gpa)<<endl;
cout<<"the maximum gpA iz : "<<max_gpa(maxgpa)<<endl;
system("pause");
}
@bilmilk Please read the post carefully before replying otherwise people won't be able to help you.
You have not returned function values.
1 2 3
int foo(){
return some_int ;
}
Check your functions average_age() , average_gpa() and max_gpa() . You have not returned values anywhere using the return keyword as shown in the sample code above.
cout<<"the average agE iz : "<<average_age(total_age,avr_age)<<endl;
cout<<"the average gPA iz : "<<average_gpa(total_gpa,avr_gpa)<<endl;
cout<<"the maximum gpA iz : "<<max_gpa(maxgpa)<<endl;
what you are doing in these lines is calling the functions to get some values .
How can you get those values if the functions are not returning anything ?
Always try to comment your code to indicate what you are actually doing. It makes things easier and also helps in long run.
Peace.