TASK: Pay for your groceries, using WHILE.
COMMENT: The Kroger automatic checkout system tells you the total price of the groceries you've bought, and then waits for you to pay. If you pay in cash, then you put the bills into the machine one at a time. The checkout system will realize when you have inserted enough bills to pay your total, and won't accept any more. Instead, it returns your change and prints a reciept.
This is another example of indefinite repetition. The machine doesn't know how many bills you will enter, or what denominations they will be. But it patiently repeats the steps of accepting a bill, adding it to the total paid, "AS LONG AS" the total paid is less than the total owed.
INSTRUCTIONS:
Let OWED represent the amount owed for the groceries, and set it as a real number between 10 and 100. You can do this by a command like OWED = 10 + 90 * random number Let PAID represent the amount you have paid so far, and initialize it. Now the checkout machine has to accept bills until satisfied: AS LONG AS the amount OWED is more than what you have PAID BILL = input ( another bill from the user, 1, 5, 10, 20, or whatever ) add BILL to the amount paid END Let CHANGE represent the change the machine owes you. PRINT PAID, OWED, and CHANGE
If it bothers you that OWED is some crazy number like 57.1234567 instead of 57.12, you can modify your program so that OWED should only have two decimal places. Just after you set OWED as describe above, do the following rounding operation:
OWED = ( round ( 100 * OWED ) ) / 100
CHECK: Here's an example of results:
>> hw028 Amount due is 59.22: Insert a bill such as 1, 5, 10, 20, 50, or 100: 20 Amount due is 39.22: Insert a bill such as 1, 5, 10, 20, 50, or 100: 20 Amount due is 19.22: Insert a bill such as 1, 5, 10, 20, 50, or 100: 10 Amount due is 9.22: Insert a bill such as 1, 5, 10, 20, 50, or 100: 10 $ 60.00 paid $ 59.22 groceries $ 0.78 change back
SUBMIT: Your work should be stored in a script file called "hw028.m". Your script file should begin with at least three comment lines:
% hw028.m % YOUR NAME % This script (describe what it does) % Add any comments here that you care to make.If this problem is part of an assignment, then submit it to Canvas.