August 2002
Beginner
1122 pages
22h 1m
English
Now that we have seen how to write the Average function, let's see how to use it to solve our original problem. The program in Figure 5.5 uses our Average function twice, once to average two weights and once to average two ages.
#include <iostream> using namespace std; short Average(short First, short Second) { short Result; Result = (First + Second) / 2; return Result; } int main() { short FirstWeight; short SecondWeight; short FirstAge; short SecondAge; short AverageWeight; short AverageAge; cout << "Please type in the first weight: "; cin >> FirstWeight; cout << "Please type in the second weight: "; cin >> SecondWeight; AverageWeight = Average(FirstWeight, SecondWeight); ... |
Read now
Unlock full access