February 26th, 2001, 09:58 PM
Vending Machine Program
Hello again. I'm working on another project now...
Thanks to everyone who helped me on the last one. I
got it all done, for the most part correctly. My
next program needs to duplicate a vending machine.
I think I am even more lost this time than the last.
Here is the exact assignment:
You are to write a program which will simulate a soft drink vending machine.
Several selections will be offered, but they vary in price. Your main() will
accept from the user the amount of money entered and the selection desired.
As long as the user continues to select a brand, the program will continue
to allow them to enter money. To quit, they need to enter 0 as their selection.
When this is done, the program will terminate without asking for money.
After the user has entered a selection and money, you will call a buy() function to buy the soft drink. If the machine has cans left for that selection, and enough money for the purchase was entered, the purchase will be made successfully, the user will be informed of how much change is returned, and will once again be prompted to enter a selection.
If the machine is out of stock, the user will be so informed and their money will be returned. If the machine has stock, but the user did not enter enough money to make the purchase, they will be so informed and their money will be returned.
The user does not know a) how many cans are available for a given brand, nor do they know b) how much a given brand costs.
Your main() will handle all user interaction (prompting for input, displaying output) and will call the buy() function to attempt the purchase. The buy() function will use a boolean return type to determine if it was successful. Your call will pass the selection from the user, the money entered, and a boolean to determine of the machine is out of stock.
The buy() function will return a boolean with a value of either true or false to indicate whether a successful purchase was made. It will also update both the money the user entered to indicate the change left, and the boolean passed to indicate whether it was out of stock or not.
The buy() function will keep track of the number of cans left in the machine for each brand via variables that are local to the buy() function.
You will be expected to solve this lab using a function call, the return value from a function, by passing arguments via value and via reference, and to use proper storage classes to limit the scope of variables.
NO "global" variables should be used, only variable that are local to their respective functions.
You should use the sample data as shown below to run your program when you
submit it for grading. HOWEVER, you should test ALL possible conditions in your
program, beyond what is shown here (that is, test for each brand carried).
You may assume that your user always enters a valid selection in main (that is,
either 1, 2, 3, or 0).
That's it. I know that nobody is probably going to read this far, as it is a lot, but if anyone does, where do I start? I know how to do the most basic stuff, like prompt the user for his inputs and everything. But I do not know how to work with booleans or how to make the program keep track of how much is in stock. If anyone could help me out at all it would be appreciated. Thanks.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!