#include <iostream>
using namespace std;
/* This function takes three integers and returns their
average value as a double. */
double average(int v1, int v2, int v3)
{
double sum;
sum = v1 + v2 + v3;
return sum / 3.0;
}
int main(void)
{
// Prompt for, and read, three integers.
cout << "Please enter three integer values: ";
int n1, n2, n3;
cin >> n1 >> n2 >> n3;
// Compute the average using the above function.
cout << "The average of " << n1 << " " << n2 << " " << n3
<< " is " << average(n1, n2, n3) << endl;
}
Performs a calculation using a function. Also note
the types in the division in the return statement.
Textbook: pp. 240–245