Change Machine

Project

Create a program that instructs the user to enter a purchase price and an amount tendered and then prints out the change in dollars, quarters, dimes, nickels, and pennies.  Be prepared to update me on your progress upon my return.

Example:  Sample input and output.

Input

Purchase price $33.27
Amount tendered $40.00

Output

Change  
dollars 6
quarters 2
dimes 2
Nickels 0
pennies 3

Directions

Complete this program as a group during the regularly scheduled class time.  I strongly recommend that you spend some time doing the calculations by hand before attempting to write the C++ source code.  This project is an exercise in problem solving.  Figuring out which calculations you want to perform should take longer than coding it in C++.  If you get stuck, consider the hint provided below.

Hint

Convert the change from dollars to cents using a data type conversion such as
changeInCents = static_cast<int>(change*100.0);
Then you can use

  1. The properties of integer division, namely that it returns an integer and discards the decimal part.  For example 7/3 = 2.
  2. The remainder operator %.