Making Change

This month’s challenge is to calculate the number of quarters, dimes, nickels, and pennies required when given a specific dollar amount. It’s something fast food cashiers should know, but apparently they don’t! So maybe your solution to this exercise could help them.

In case you’re unfamiliar, the coinage in the United States goes like this:

One quarter equals 25¢ or .25 dollar
One dime equals 10¢ or .10 dollar
One nickel equals 5¢ or .05 dollar
One penny equals 1¢ or .01 dollar

Take a dollar amount, say $1.31. That’s one dollar, one quarter, one nickel, and one penny. But in coins it could be:

5 quarters, $1.25
1 nickel, $0.05
1 penny, $0.01

Total = $1.31

Your task is to code a program that takes a specific dollar amount and determines how many quarters, dimes, nickels, and pennies are required to equal that total.

You don’t need to work out all the permutations. While that would be fun, it’s more than I’m asking for. Instead, code something that generates output such as this:

Making change for 131 cents:
 5 quarters
 0 dimes
 1 nickels
 1 pennies

You can set the initial amount (131 above) to whatever you like, but the code should always report back the number of quarters, dimes, nickels, and pennies required to equal that amount.

Please try this Exercise on your own before you view my solution.