MATLAB CODE 30. Write a program that determines the change given back to a custo
ID: 3706119 • Letter: M
Question
MATLAB CODE
30. Write a program that determines the change given back to a customer in a self-service checkout machine of a supermarket for purchases of up to S The program generates a random number between 0.01 and 50.00 and dis- plays the number as the amount to be paid. The program then asks the user to enter payment, which can be one S1 bill, one $5 bill, one $10 bill, one $20 bill, or one $50 bill. If the payment is less than the amount to be paid, an error message is displayed. If the payment is sufficient, the program calcu- lates the change and lists the bills and/or the coins that make up the change, which has to be composed of the least number each of bills and coins. For example, if the amount to be paid is $2.33 and a $10 bill is entered as pa ment, then the change is one $5 bill, two $I bills, two quarters, one dime, one nickel, and two pennies. Execute the program three times.Explanation / Answer
SAVE THE FOLLOWING CODE IN MATLAB AND GET THE RESULTS-
clc
clear
close all;
a=0.01+(50-0.01)*rand(1,1);
fprintf('The amount to be paid is $%6.2f ',a)
A=input('Enter the payment is $: either 1 or 5 or 20 or 50');
while a>A
fprintf('Error: You have entered the payment which is less then the amount to be paid')
A=input('Enter the payment is $: either 1 or 5 or 20 or 50');
end
change=A-a;
fprintf('The amount given to the customer is %6.3f ',change)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.