{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# solution2 - #dimes ← integer part of(change.10 change ←...

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

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)

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

View Full Document
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern