Fewest Coins Possible: The idea for this project is that we ask the user for the amount of change they have (let's assume it's $1 or less) and we figure out the fewest number of coins needed to total that amount. Now if you remember from the "Equally Divide" project we calculated a remainder as "Left Over" -- and this is similar to that. We will calculate the number of quarters needed, get the remainder, divide that by the number of dimes, etc.
- Set up variables for each coin type: Quarters, Dimes, Nickels, and Pennies
- Set up a variable for the currentCents
- Ask users to enter the amount of cents ($1 would be 100, for example)
- Calculate Quarters first, then find the remainder and set currentCents to the remainder amount
- Calculate Dimes from the remainder (again currentCents)
- Continue with Nickels and Pennies
- Display the results like, "Quarters: xx"
- Amounts to try: 91, 41, 59, 6 (and obviously others)
No comments:
Post a Comment