You are on page 1of 4

# McCoy, Daniel

CISP 300
Assignment 6

Statement of Problem
Design an algorithm for the following problem You are in a candy store. Each of your customers buys exactly one
item costing \$1.00 or less. Each customer pays for the item with exactly \$1.00. Your job is to give each customer the
right amount of change in some combination of quarters, dimes, nickels, and pennies. The combination must be the
minimum number of coins. The input is composed of customer records, each containing customer name, and item
cost. The output is composed of lines, each containing customer name, item cost, change, number of quarters,
number of dimes, number of nickels, number of pennies. A cost of \$0.00 will be used to signal the end of the input.

Table of Variables
Variable Name Type Range Description
NAME String A-Z, a-z The customer name
COST Number 0-1 The cost of the item
CHANGEP Number 0-1 The permanent change value
CHANGE Number 0-1 The amount of change
QUARTER Number 0-4 The number of quarters
DIME Number 0-2 The number of dimes
NICKEL Number 0-1 The number of nickels
PENNY Number 0-4 The number of pennies
Pseudocode

START
WRITE "Enter: Name, Cost"
DOWHILE COST > 0
QUARTER = 0
DIME = 0
NICKEL = 0
PENNY = 0
CHANGE = 1 - COST
CHANGEP = CHANGE
DOWHILE CHANGE >= 0.25
CHANGE = CHANGE - 0.25
QUARTER = QUARTER + 1
ENDDO
DOWHILE CHANGE >= 0.10
CHANGE = CHANGE - 0.10
DIME = DIME + 1
ENDDO
DOWHILE CHANGE >= 0.05
CHANGE = CHANGE - 0.05
NICKEL = NICKEL + 1
ENDDO
DOWHILE CHANGE > 0
CHANGE = CHANGE - 0.01
PENNY = PENNY + 1
ENDDO
WRITE "Customer Name: ", NAME
WRITE "Item Cost: ", COST
WRITE "Change: ", CHANGEP
WRITE "Number of quarters: ", QUARTER
WRITE "Number of dimes: ", DIME
WRITE "Number of nickels: ", NICKEL
WRITE "Number of pennies: ", PENNY
WRITE "-------------------------------"
ENDDO
Qbasic Source Code

CLS
PRINT "Enter: Name, Cost"
INPUT NAME\$, COST
DO WHILE (COST > 0)
QUARTER = 0
DIME = 0
NICKEL = 0
PENNY = 0
CHANGE = (1 - COST)
CHANGEP = CHANGE
DO WHILE (CHANGE >= .25)
CHANGE = (CHANGE - .25)
QUARTER = (QUARTER + 1)
LOOP
DO WHILE (CHANGE >= .1)
CHANGE = (CHANGE - .1)
DIME = (DIME + 1)
LOOP
DO WHILE (CHANGE >= .05)
CHANGE = (CHANGE - .05)
NICKEL = (NICKEL + 1)
LOOP
DO WHILE (CHANGE > 0)
CHANGE = (CHANGE - .01)
PENNY = (PENNY + 1)
LOOP
PRINT "Customer Name: ", NAME\$
PRINT "Item Cost: ", COST
PRINT "Change: ", CHANGEP
PRINT "Number of quarters: ", QUARTER
PRINT "Number of dimes: ", DIME
PRINT "Number of nickels: ", NICKEL
PRINT "Number of pennies: ", PENNY
PRINT "-------------------------------"
INPUT NAME\$, COST
LOOP
END
Program Output:

## Enter: Name, Cost

? Bill,.23
Customer Name: Bill
Item Cost: .23
Change: .77
Number of quarters: 3
Number of dimes: 0
Number of nickels: 0
Number of pennies: 2
-------------------------------
? Sam,.51
Customer Name: Sam
Item Cost: .51
Change: .49
Number of quarters: 1
Number of dimes: 2
Number of nickels: 0
Number of pennies: 4
------------------------------- Not sure what this is all about
? Sue,.97
Customer Name: Sue
Item Cost: .97
Change: 2.999997E-02
Number of quarters: 0
Number of dimes: 0
Number of nickels: 0
Number of pennies: 3
-------------------------------
? Richard,0