Write a C program that asks the user to enter five integer m
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.
Solution
Solution.cpp
#include <iostream>//header file for inputr output function
#include <iomanip>//header forset precision
using namespace std;//it tells the compiler to link std namespace
float AVG(int,int,int,int,int);//function declaration
float avg;
int main()
{//main function
int mark1,mark2,mark3,mark4,mark5;
cout<<\"Enter marks 1:\";
cin>>mark1;//keyboard inputting
cout<<\"Enter marks 2:\";
cin>>mark2;//keyboard inputting
cout<<\"Enter marks 3:\";
cin>>mark3;//keyboard inputting
cout<<\"Enter marks 4:\";
cin>>mark4;//keyboard inputting
cout<<\"Enter marks 5:\";
cin>>mark5;//keyboard inputting
AVG(mark1,mark2,mark3,mark4,mark5);//function calling
cout<<\"Average marks is :\"<<avg<<endl;
return 0;
}
float AVG(int a,int b,int c,int d,int e)
{//function definition
cout << fixed;
cout << setprecision(2);
avg=(a+b+c+d+e)/5;
return avg;
}
output
Enter marks 1:97
Enter marks 2:98
Enter marks 3:90
Enter marks 4:99
Enter marks 5:95
Average marks is :95.00
