In: Electrical Engineering
Is there a solution for this anywhere? Chapter 9, Problem 16P, 5th edition, Matlab for engineers
Matlab Code:
---------------------------------------------------------------------------------------------------------------------------------------------------------
% 9.16 A store owner asks you to write a program for use in the checkout process.
% The program should:
% • Prompt the user to enter the cost of the first item.
% • Continue to prompt for additional items, until the user enters 0.
% • Display the total.
% • Prompt for the dollar amount the customer submits as payment.
% • Display the change due.
clc;clear;
rate = input ('enter the cost of first item = ')
totalCost = 0;
quantity = 1;
while(quantity ~= 0)
quantity = input('Enter the no of quntity you want to add = ')
totalCost = totalCost + rate * quantity;
end
sprintf('Total Cost of purchase is = %d',totalCost)
cash = input('Enter the dollar amount to submit as payment = ')
sprintf('The change due is %d',cash - totalCost)
---------------------------------------------------------------------------------------------------------------------------------------------------------