solution2 - #dimes integer part of (change / .10) change...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 2  -- Solutions For both exercises, the algorithm shown is one of many possible valid algorithms that will solve the problem. 1. First Refinement a) get the total bill and the amount paid by the customer b) compute the total amount of change to return to the customer c) divide the change into dollar bills, quarters, dimes, nickels and pennies Second Refinement a) get the total bill and the amount paid by the customer cost the total bill cash the amount of cash paid by the customer b) compute the total amount of change to return to the customer change cash - cost c) divide the change into dollar bills, quarters, dimes, nickels and pennies #dollars the integer part of change change change - #dollars #quarters integer part of (change / .25) change change - (#quarters x .25)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #dimes integer part of (change / .10) change change - (#dimes x .10) #nickels integer part of (change / .5) #pennies change - (#nickels x .5) 2. First Refinement a) get the number N b) compute N! c) display the result Second Refinement a) get the number N N number given by the user b) compute N! product 1 repeat for i=1, 2, 3, . .., N product product * i c) display the value of product Better Refinement a) get the number N N number given by the user b) compute N! product 1 i 1 repeat while i <= N product product * i i i + 1 c) display the value of product This version is better than the Second Refinement above because it doesn't include the ellipsis (i.e., . ..). The ellipsis leaves room for ambiguity and it not something that a computer understands....
View Full Document

This homework help was uploaded on 04/16/2008 for the course CSCI 1100 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 2

solution2 - #dimes integer part of (change / .10) change...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online