22.6k views
2 votes
Edhesive AP Computer Science Coding Activity 2:

Write a method that takes 5 ints as parameters and returns the average value of the 5 ints as a double.
This method must be named average() and it must have 5 int parameters. This method must return a double.

Calling average(1, 5, 7, 4, 10) would return 5.4.

You can call your method in the program's main method so you can test whether it works, but you must remove or comment out the main method before checking your code for a score.

User Beny Lim
by
5.2k points

1 Answer

9 votes

Answer:

The method in C++ is as follows:

double average(int v, int w, int x, int y, int y){

double ave = (v+w+x+y+z)/5.0;

return ave;

}

Step-by-step explanation:

This defines the average method with 5 parameters

double average(int v, int w, int x, int y, int y){

This calculates the average

double ave = (v+w+x+y+z)/5.0;

This returns the calculated average

return ave;

}

To call the method from the program's main, use:

int main(){

cout<<average(1,5,7,4,10);

return 0;

}

User MatterGoal
by
4.8k points