Assignment 04

Now you will notice that there is yet another number at the end of each line. This is the "USDA Standardized Metabolic Weight Loss Multiplying Gorgification Factor"1 for each item on the list of options1. If you multiply this integer by a person's customer's metabolic rate, then the result will be the number of pounds the customer will lose as a result of eating the vended item1. Coooool! So, at the beginning of the program, you should prompt the user for his/her/its metabolic rate, a value that falls between and including 0.05 and 0.09. That value should only be prompted for once in the run of the program. The result of this is that the machine user will be able to track how much weight they stand to lose1.

Specifications: Your program is to present the user of the program with a menu of options as if they were looking at a vending machine. They should make (input) a choice of the item they want, be prompted for and then enter (on the keyboard, not an actual physical offering) the stated cost of the item or a greater amount for which they will receive change. Your program will not allow invalid item choices, nor allow sub-price offerings to relieve the incurred debt burden as a result of that choice (reject less money than the cost). In other words, your program is to check inputs and re-prompt for proper inputs whenever possible. Also, your program will present the menu once again after any transaction is completed (choice made, money input, change given) with the program ending only if the 'quit' option is chosen.

Your menu should look something like this (with these specific choices):

Due: Monday, Feb. 19, 2018 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.

Background: Your last assignment was to exercise your rights to make decisions and act upon them. You practiced using "decision branching" in programming - the use of the if-else structure. Now, you know all about looping and what you can do with repeated processes. So you're going to code up a simulated vending machine. This would act like a vending machine for BoJack and his hybrid friends. Mostly it's for BoJack as he has gained unsightly pounds eating junk food from the usual run-of-the-mill candy bar vendors around the town of Atlantis. His mother, an old nag, nags him about his problems. Nag, nag, nag (see picture at right). With loops in c++ you no longer have to tolerate unrealistic inputs, you can iterate over computations, you can ask users to make choices until the cows come home, and much more!

Options

----------

1. Dry Hay $1.50 34

2. Wet Hay $1.25 33

3. Kale $0.75 26

4. Ground Corn $2.50 12

5. Carrots $1.00 25

6. Carrots $1.00 25

7. Carrots $1.00 25

8. Industrially Milled Fortified Sawdust Horse Feed $0.50 13

9. Quit

As for the output, when a valid option is chosen, your code should output a statement something like, "you chose Kale...deposit $0.75 please". If the amount entered by the user is not enough, then your code should give an appropriate error message (e.g. "not enough, please give till it hurts") and have them re-enter the expected amount and continue to do so until they pay up! (they can't back out of the sale); if enough or more, then it should say "your change is ... ". Also, you should also output a statement about how much weight the user will lose by eating the item (e.g. "you will lose .68 lb eating this Kale").

When you submit: As usual, we want you all to input the same values. Do this:

    • enter metabolic rate of 0.04

    • enter metabolic rate of 0.06

    • choose option 0 (you better have an error message for the user!)

    • choose option 2

    • enter negative one dollar

    • enter $1.25

    • choose option 4 and enter $2.50

    • choose option 6 and enter $0.50, and then enter enough!

    • choose option 8 and enter $4.00

    • quit

As always, ask if you need help.

1Pure nonsense. Don't believe a word of this tripe2.

2Cow's intestines.

Doing this will make all of your output (after this code) have exactly 2 dec. places. Thus, the output of three and a half dollars look like $3.50 instead of $3.5, which looks cheesy.

Your output will necessarily include statements of monetary value, such as $5.00 or $4.50 or even the much more confusing $4.75. In order to make your output of money have exactly 2 decimal places, put this "magic code" (we'll explain later) before such output:

cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);

Details: Once again, every input by the user needs to be range checked for validity. You are required to use the switch-case statement to handle the decision branching for the menu. If you find a reason/way to use it anywhere else in the program, that's fine too, but it is not required. Be sure to set up constants for everything that might change. For example, we just might change the first option in the list to be "Stuff", costing $4.00 with a factor of 55. You want the change to be easy! Make your outputs easy to read and friendly....even if you are demanding money in return for inedible garbage.