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

This is a matlab question i need help with this. i can\'t get it to work Write a

ID: 3809816 • Letter: T

Question

This is a matlab question i need help with this. i can't get it to work

Write a program that determines the change given back to a customer in a self-service checkout machine of supermarket for purchases of up to $50. The program generates a random number between 0.01 and 50.00 and displays the number as the amount to be paid. The program then asks the user to enter payment, which can be one $1 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 is displayed. If the payment is sufficient, the program calculates 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 payment, then the change is one $5 bill, two $1 bills, two quarters, one dime, one nickel, and two pennies. Execute the program three times. Answer: The amount to be paid is: $13.93 Please enter payment in dollars (1, 5, 10, 20 or 50) 20 The change is: 0 $20 bills 0 $10 bills 1 $5 bills 1 $1 bills 0 quarters 0 dimes 1 nickels 2 cents

Explanation / Answer

Here is the working code for you:

amount = round(rem(rand * 100, 50) * 100) / 100;

fprintf('The amount to be paid is: $%4.2f ', amount);

payment = input('Please enter payment in dollars (1, 5, 10, 20, or 50): ');

balance = payment - amount;

twentyDollarBills = 0;

tenDollarBills = 0;

fiveDollarBills = 0;

oneDollarBills = 0;

quarters = 0;

nickels = 0;

dimes = 0;

cents = 0;

if balance < 0

fprintf('You paid insufficient amount.... ');

return;

else

if balance >= 20

twentyDollarBills = floor(balance / 20);

else

twentyDollarBills = 0;

end

balance = balance - twentyDollarBills * 20;

if balance >= 10

tenDollarBills = floor(balance / 10);

else

tenDollarBills = 0;

end

balance = balance - tenDollarBills * 10;

if balance >= 5

fiveDollarBills = floor(balance / 5);

else

fiveDollarBills = 0;

end

balance = balance - fiveDollarBills * 5;

if balance >= 1

oneDollarBills = floor(balance);

else

oneDollarBills = 0;

end

balance = balance - oneDollarBills;

if balance >= 0.25

quarters = floor(balance / 0.25);

else

quarters = 0;

end

balance = balance - quarters * 0.25;

if balance >= 0.10

dimes = floor(balance / 0.1);

else

dimes = 0;

end

balance = balance - dimes * 0.1;

if balance >= 0.5

nickels = floor(balance / 0.05);

else

nickels = 0;

end

balance = balance - nickels * 0.05;

if balance >= 0.01

cents = floor(balance / 0.01);

else

cents = 0;

end

fprintf('The change is: ');

fprintf('%d $20 bills %d $10 bills %d $5 bills %d $1 bills ', twentyDollarBills, tenDollarBills, fiveDollarBills, oneDollarBills);

fprintf('%d quarters %d dimes %d nickels %d cents ', quarters, dimes, nickels, cents);

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote