value returning in function
Apr 25, 2013 at 7:14pm UTC
I have written this function to find the over all class average, so how can i pass the avg value to another function??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
double OverallClassavg (student details[])
{
double total=0.0;
double avg=0.0;
for (int i=0; i < size; i++)
{
total += details[i].overall;
}
avg=total/size;
cout<< "Over all class average : " << avg <<endl;
return avg;
}
Apr 25, 2013 at 7:18pm UTC
1 2 3 4 5 6 7 8
int main()
double details[5] = {1, 2, 3, 4, 5};
double averageAmount = OverallClassavg(details[]);
std::cout << averageAmount << std::endl;
//or
double details[5] = {1, 2, 3, 4, 5};
std::cout << OverallClassavg(details[]) << std::endl;
Apr 25, 2013 at 7:48pm UTC
How can i reuse the avg in another function??
example:
1 2 3 4 5 6 7 8 9 10 11
void listofStudentsAboveClassAvg (student details[], double avg)
{
cout<< "List of students above the class average" <<endl;
for (int i=0; i < size; i++)
{
if (details[i].overall < avg)
{
cout<<details[i].fname<<" " <<details[i].lname<< " - " <<details[i].overall<<endl;
}
}
}
like this??
Apr 25, 2013 at 7:54pm UTC
um you would have to do
1 2 3 4
int maint()
{
listofStudentsAboveClassAvg(details[],OverallClassav(details[]));
}
or you can of course initialize a variable and set it equal to the class average and then put then use that as a paramater in your list of students above average function
Apr 26, 2013 at 3:29pm UTC
I tried it's not working !!!!
Any other ways??
Topic archived. No new replies allowed.