CPSC170A
Fundamentals of Computer Science II

Lab 5

Fruitful Functions

Average

Details

Write the function average(double value1, double value2, double value3), that returns average of the three parameters.

Example

The function calls:

average(0.0, 0.0, 0.0)
average(1.0, 0.0, 0.0)
average(0.0, 1.0, 0.0)
average(0.0, 0.0, 1.0)
average(1.0, 2.0, 3.0)

Would produce the output:

0
0.333333
0.333333
0.333333
2


Change

Details

Create the function count_coins(int cents) that returns the fewest number of coins needed to make change. The parameter cents, an integer between 0 and 100, is the amount of change in cents. The function should return an integer representing the fewest number of coins, using the American monetary system consisting of quarters, dimes, nickles, and pennies, necessary to make the specified amount of change.

Example

The function calls:

count_coins(0)
count_coins(1)
count_coins(5)
count_coins(7)
count_coins(18)
count_coins(42)
count_coins(91)

Would produce the output:

0
1
1
3
5
5
6