Programming Exercise — Correct Change

When cashiers make change they first try to "fit" dollars into the amount you get back, then try to fit quarters (25 cent coins) into what is left over, they try to fit dimes (10 cent coins) into what is now left over, then try to fit nickels (5 cent coins) into what is left, and finally are left with a few odd cents. For example, say that your change is 163 cents:

Your change is : 1 dollar, two quarters, one dime, and three cents.

Write a program that reads how much change is due (in cents) and writes out that amount as dollars, quarters, dimes, nickels, and pennies. Use integers for all variables and all arithmetic. If you are stuck, do an example problem with paper and pencil.

  1. Use the echo program as an example of how to write input and output statements
  2. Instead of reading in a String you will need to read in a whole number
    the method of the Scanner to read in a number is called nextInt()
  3. You will need to use the / operator to find out how many of each demonimation can be fit into the amount of money you have
  4. You will need to use the % operator to find out how much change is left after each coin has been used up.

echo code

This is just an example - your program will be different

Here is some video help to get you going:

  1. Part 1 : setting up the program to read a whole number as input
  2. Part 2: calculating the amount of change