Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab Problem: please use matlab format, thank you in advance! Problem 5 (1 poi

ID: 3705930 • Letter: M

Question

Matlab Problem: please use matlab format, thank you in advance!

Problem 5 (1 point. Instructor's Initials A grocery store owner has asked you to develop a program for use in the checkout process. The program should a) Prompt the cashier to enter the cost of the first item b) Continue to prompt for additional items until the cashier enters 0 c) Display the total d) Prompt for the amount the customer submits as payment e) Display the change due All money displays should have dollar signs and 2 digits after the decimal (i.e. $27.32, not 27.3200000). If the cashier accidently enters a negative value, the program should not accept the value as part of the total, nor should it stop or crash. Instead it should remind the cashier that there are no negative prices in the store, and keep working (hint: use the continue instruction). Demonstrate operation to the instructor, and print a copy of the program to attach to the lab.

Explanation / Answer

#Matlab script that prompts user to enter grocery item until user enters 0 to quit and

#find the total cost, and prompt for payment amount and then find the change

#grocerry.m

#totalCost=0
totalCost=0;
#Set grocerryItem=0
grocerryItem=0;
#payment=0
payment=0;
#prompt for price of the grocery item
grocerryItem=input('Enter price of grocerry item or 0 to stop : ');
while grocerryItem!=0
#check if grocerryItem is negative
#reprompt for grocerry item
while grocerryItem<0
fprintf('Negative amount is not allowed ');
grocerryItem=input('Enter price of grocerry item or 0 to stop : ');   
end
#add grocerryItem to totalCost
totalCost+=grocerryItem;
#prompt for grocerryItem
grocerryItem=input('Enter price of grocerry item or 0 to stop : ');
end
  
#read payment
payment=input('Enter payment $:');
#calculate change
change=payment-totalCost;

fprintf('Total Items Cost :$%5.2f ',totalCost);
fprintf('Payment :$%5.2f ',payment);
fprintf('Change :$%5.2f ',change);

-----------------------------------------------------------------------------

Sample Output :

Enter price of grocerry item or 0 to stop : 10
Enter price of grocerry item or 0 to stop : 20
Enter price of grocerry item or 0 to stop : 30
Enter price of grocerry item or 0 to stop : 0
Enter payment $:100
Total Items Cost :$60.00
Payment :$100.00
Change :$40.00