function problem in structure

the programme is nOt compiling ..........the main problem is with functions!!!!
have a Look......here is the code :


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
#include<iostream>
#include<conio.h>
using namespace 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;
}
} 
} 
You have not returned function values.
1
2
3
int foo(){
  return some_int ;
}

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");
}




these r the returned values in code on line 42-45
Hey you haven't declared the variables (total_age, avr_gpa, total_gpa, avr_age, maxgpa), which are passed to the function calls.
@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.
Topic archived. No new replies allowed.