2 dimes 1 nickels 4 pennies This algorithm will determine how to make change for an amount of in US currency. In this case, it will start with all pennies, then attempt to substitute larger coins up through quarters. Depending on how comfortable students are with modulus and integer division, there are a couple different ways to approach making the algorithm better. The first answer is longer, but it doesn’t use modulus and integer division. Get a value for (in cents) change Set to pennies change Set to 0 nickels, dimes, quarters While (change >= 25) Set to + 1 quarters quarters Set to - 25 change change (change >= 10) Set to + 1 dimes Set to - 10 change change While (change >= 5) Set to + 1 nickels nickels Set to - 5 change change Set to pennies change Print change is” “Your the value of and quarters “quarters” Print the value of and dimes “dimes” the value of and nickels “nickels” Print the value of and pennies “pennies” If you are comfortable with modulus and integer division, you could do Get a value for (in cents) change
2 dimes 1 nickels 4 pennies This algorithm will determine how to make change for an amount of in US currency. In this case, it will start with all pennies, then attempt to substitute larger coins up through quarters. Depending on how comfortable students are with modulus and integer division, there are a couple different ways to approach making the algorithm better. The first answer is longer, but it doesn’t use modulus and integer division. Get a value for change (in cents) Set pennies to change Set nickels, dimes, quarters to 0 While (change >= 25) Set quarters to quarters + 1 Set change to change - 25 (change >= 10) Set to dimes + 1 Set change to change - 10 While (change >= 5) Set nickels to nickels + 1 Set change to change - 5 Set pennies to change Print “Your change is” the value of quarters and “quarters” Print the value of dimes and “dimes” the value of nickels and “nickels” Print the value of pennies and “pennies” If you are comfortable with modulus and integer division, you could do Get a value for change (in cents)
Solution-Manual-Invitation-to-Computer-Science-6th-Edition-Schneider.docx