Answered! The purpose of this exercise is to practice on using user defined value returning functions. Write a C++ program that asks the user to enter five integer marks and find out the average of the five marks….

The purpose of this exercise is to practice on using user defined value returning functions.

Write a C++ program that asks the user to enter five integer marks and find out the average of the five marks.

Please note that you will pass the five marks to a function called AVG(int, int, int, int, int) to calculate the average and return the average to the calling function, the main() function.

Print out the average in the main() function.

Compile and run the C++ program.

Expert Answer

 In the following code AVG function is used to calculate the average of 5 numbers and is called from main function.The resultant average is printed in main function.

The user is asked to enter 5 numbers one by one and then the entered values are passed to AVG function which will calculate the average and will give the value to calling function.

#include<iostream.h>
#include<conio.h>
int AVG(int,int,int,int,int);
void main()
{
int u,w,x,y,z;
cout<<“Enter ist number : “<<endl;
cin>>u;
cout<<“Enter 2nd number : “<<endl;
cin>>w;
cout<<“Enter 3rd number : “<<endl;
cin>>x;
cout<<“Enter 4th number : “<<endl;
cin>>y;
cout<<“Enter 5th number : “<<endl;
cin>>z;
int result=AVG(u,w,x,y,z);
cout<<endl<<“Average of the numbers is : “<<result;
getch();
}
int AVG(int u,int w,int x, int y, int z)
{
int average=(u+w+x+y+z)/5;
return average;
}

Still stressed from student homework?
Get quality assistance from academic writers!