Friday, September 13, 2013

Flow Chart & Code Homework

Here's another challenge that might be fun to try -- and will help keep you "code-limber".  :)

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)
This program is definitely possible for you to complete knowing what you already know.

No comments:

Post a Comment