Value Returning Function Exercise: avg()
In this exercise you will practice writing and using value returning functions by writing a C++ program that asks the user to enter five integer marks, uses a function to calculates the average of the five marks, then prints the average.
- Create a C++ program named
ex3_average.cpp
in the Visual Studio project or create it in your IDE. - Declare 5 integers in
main()
. - Prompt for and read five integer marks in
main()
. - Write and use a value returning function with five integer parameters to calculate and
return the average to the calling function,
main()
.
Here is a partial prototype for you to use:
Be sure the calculation in the function produces decimal places for a more precise average. You must determine a return type that will preserve those decimal places.avg(int, int, int, int, int); - Print the average in the
main()
function. - Compile and run the C++ program.
- Test the program with an input guaranteed to produce decimal places. For example:
Please enter 5 integer marks: 1 2 1 1 1 The average of those marks is: 1.2
When you are done:
- Take a screenshot of your IDE and console window after compiling and running the program.
- For this exercise, you will have:
ex3_average.cpp
. - If you have completed everything, congratulations! Please upload .cpp files and screenshots to URCourses.