Chapter 5 - Worked Examples
Exercise - Change Calculator
Imagine you are running a convenience store. It is not unusual for customers to pay above their total shopping cost – requiring you to return the change.
For example, a customer may have bought several items totalling to â‚©10,540, to which he pays â‚©11,000. You are obliged to return the change, â‚©460, to the customer. This is done by returning:
Four â‚©100 notes
One â‚©50 coin
One â‚©10 coin
Create a program that can assist you in finding out how to provide change to a customer.
Specifications
The program should ask the user to enter:
An integer representing the change, in won.
You may assume that this number will always be greater than or equal to zero
The currency notes that the program supports as change should be:
â‚©5,000 note
â‚©1,000 note
â‚©500 coin
â‚©50 coin
â‚©10 coin
Any values that cannot be represented (for example â‚©2), should be rounded down.
Example
Enter an amount in won : 9540
You can provide this change as follows:
â‚©5000 : 1
â‚©1000 : 4
â‚©500 : 1
â‚©50 : 0
â‚©10 : 4Last updated
Was this helpful?