Project # 1
40 points
Objectives
You are asked to write a program that computes how to dispense change after a purchase. The learning objective for this assignment is to implement your first project using sequential algorithm. A sequential algorithm is the simplest find a algorithm because it just executes a series of statements one right after the other. You are not required to use any decision making or looping in this projects. The statements executed are the same every time.
Discussion
In the United States, use the following denominations of paper and coins. Larger denominations such as $50, $100, $500, $1000, $5000 and $10000 bills are printed by the government but not typically dispensed as change by retail establishments.
Denomination | Value (dollars) |
penny | $0.01 |
nickel | $0.05 |
dime | $0.10 |
quarter | $0.25 |
dollar | $1.00 |
five | $5.00 |
ten | $10.00 |
twenty | $20.00 |
The program should prompt the user for the amount of purchase, the amount of cash tendered, and then output the change by the number of coins or bills to dispense. For the purposes of this project, make all your denominations plural even through it is incorrect English. Also, in order to keep the program strictly sequential, print out denominations even when they are zero.
Algorithm
You are to design your own algorithm for this project, but here are some technical hints to get around issues that you will run into. A major part of the project is to figure out how many of a denomination can fit into an amount, and what amount is left over after taking out the denomination. In C, this is accomplished using two operators. The division / operator can tell you how many of a denomination fit into an amount if it is used with integer operands. The modulo % operator can tell you the amount left over after an integer division. Since both operators require integer operands, it is much easier to implement an algorithm in C using amounts in cents rather than dollars. Allow the user to enter the amount of sale and amount tendered in floating point, but convert to cents by multiplying by 100 and converting to integer before trying to calculate denominations. For example, we know that $28.63 should yield 1 twenty with $8.63 left over. This is calculated by 2863 / 2000 = 1, and the remaining change is obtained by 2863 % 2000 = 863.
[By the way, this problem is so common that IBM mainframes have a special storage format, called packed decimal, that converts all numeric amounts to integers by moving the decimal point. All monetary calculations are performed in cents to avoid round-off errors.]
Sample Run
Amount of sale ($): 21.37
Cash Tendered ($): 50.00
Change:
1 twenties
0 tens
1 fives
3 ones
2 quarters
1 dimes
0 nickels
3 pennies
At the top of this program put following comments:
Your Name
Project Number
Date
Upload your electronic copy of your Source File named project1.c by 11pm on the due date.
Grading scheme:
Correct Result 20pts
Readability (code and output) 20pts