The goal of this programming assignment is to develop a program for counting change from a vending machine.
As an interesting aside, this can actually be a relatively difficult task if we were doing it with arbitrary currency values (for example: 57-cent, 31-cent, 7-cent, and 3-cent coins!). However, it becomes immensely more simple when we use the "round" values found in American (and many other) currency (e.g., pennies, nickels, dimes, quarters, and so forth).
At the beginning, the program should print out your Name and UARK ID number. The user should then be prompted to choose one of three types of beverages to purchase:
Then, the program should announce how much the charge will be, and ask the user how much money they are depositing in US currency. (Utilize basic error-checking and looping to force a positive value to be entered before continuing.) The program will then calculate the change the user is owed.
Importantly, the change MUST be displayed in terms of dollars and coins. We will use standard American currency, so $1.00 = 1 dollar, $0.25 = 1 quarter, $0.10 = 1 dime, $0.05 = 1 nickel, and $0.01 = 1 penny. For example, if we wanted a liter of cola and put in $5.30, the program would tell us that our change was 2 dollars, 3 quarters, 1 nickel, and 3 pennies.
Looking at the requirements above, try to sketch out the "flow"
of the program using either a diagram or a sequence of conditional
statements written in pseudo-code. Mentally walk through each of
the possible paths, and think about what conditions and calculations
need to be performed. The following algorithm description is designed
to help you along in this process.
|An algorithm is a step-by-step procedure, composed of a finite list of well-defined instructions, used to accomplish some task.|
To simplify the design, we will use what is called a "greedy algorithm." That is, we will make the best possible (i.e., optimal) choice that we can for each given step as we go. In terms of calculating a vending machine's change, we will do the following:
Start your program with comments based on your design and (the following cannot be emphasized enough..) add portions of code a little at a time. Compile and run your program on a regular basis, so you always have something that runs, even if it only does part of the job. Make sure you have completed the first task, e.g., printing your name to the screen, before you start writing code for the second task.
Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. For debugging purposes, it is useful to "echo" any variables you input, and to print intermediate results as they are calculated.
You should comment out your debugging code before you hand in your final version of the program.
When you have completed your C++ program, write a short report (less than half of a page long; a few sentences will suffice) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems?
Include this report in the comments at the top of your source code file.
NOTE: In the future, we will use Turing's PC2 submission system to submit homework assignemnts. (Snow gets in the way of everything!) For homework 2, we will do something different...
To Submit Homework 2:
(Note: Do not add anything extra to the body of the email! And make sure your FULL name and uark ID number are printed out at the beginning of your program...)
The date/time-stamp on your email will be used to verify that you met the due date above. All late projects will receive reduced credit (10% off if less than 24 hours late, no credit if more than 24 hours late), so hand in your best effort on the due date.