For your first program, you will be writing a basic interaction with the user that performs a simple computation and produces formatted output. The basic idea is that you will ask the user how many items s/he wishes to buy and what the price of those items is. In this case, though, the items are on a "buy two, get one free" sale, essentially making every third item free. An example of the interaction is given below. The user's responses are in italics.
Today we are having a "Buy Two, Get One Free" sale on our popular line of widgets.
Would you like to buy some widgets today? y
Would you like the small widgets ($3.95), the medium widgets ($5.95) or the large widgets ($8.95)?
Please enter s, m or l : s
How many widgets would you like? 4
4 small widgets (regular price) $ 15.80
1 free $( 3.95)
1. If the user's first response is 'y' or 'Y', you should continue with the program. If the response is anything else, print out a message like "Thank you. Maybe next time." and skip the rest.
2. For the second response, if the user enters 'm' or "M", give the medium widgets. If the response is 'l' or 'L', price the large widgets. For any other response, give them small widgets.
3. If the user enters a negative quantity of widgets, assume the response is zero and proceed accordingly.
4. The output should be a printout exactly as shown above. The first line should contain the quantity ordered and the words "small", "medium" or "large" as shown. The second line should indicate how many are free and deduct that amount. Line up the dollar signs using tab characters. You will need to use the setw () manipulator to get the decimal points of the prices to line up. Indent the output as shown. The line of dashes above the total is just that, a line of dashes '-'.
Include the following code
(just after your variable declarations) to insure that your numbers print out
without scientific notation and with just two decimal places.
You will need to include the
at the beginning of your program. This is necessary to make the setw () command work.
7. Use appropriate names for your variables. Include your name as a comment at the top of your code.
8. Turn in a copy of your program as well as copies of several executions. Use the cat command ( $cat myfile.cpp) to list the program. Then run it several times. If you are using PC320 from a campus machine, you can just highlight the area you wish to print and hit the print button on the left side of the window. If you are using telnet, highlight the area and copy the code into Notepad, Word or any other word processor. You can print it from there. (The copy command in telnet is found by clicking the icon at the top left of the telnet window and choosing Edit, then Copy.) If you copy your code into Word, choose a font like Courier that does not use proportional spacing. Otherwise, you won't see that you output lines up.
Due in class, Tuesday, February 22