One-Function Average
#include <iostream> using namespace std; /* This function takes three integers and returns their average value as a double. */ double average(int n1, int n2, int n3) { double sum; sum = n1 + n2 + n3; 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