Matlab cash register problem Syntax
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Using either codes from Parts A or B, adjust the m-‐‑file in a way such that it will calculate the cost of the scanned item, store it, and provide a running total of the bill as each item in scanned. The Code I have (Which works):
disp('What is the price of the item?');
x = input('');
clc;
disp('What type of item is it?');
disp('1. for Luxury Items');
disp('2. for Food or Medical Items');
disp('3. for All Other Items');
y = input('');
switch y
case 1
z=(x)+(x*0.11);
case 2
z=x;
otherwise
z=(x)+(x*0.07);
end
clc;
disp('The Total Cost of the Item (Dollars):');
disp(z);
What I'm confused about it how to loop the function so that it saves the previous amount (with tax added) and then once I prompt that I don't have any more items it will display the total. This is what I've been playing with but I'm a little lost at this point.
disp('Do you have more items?');
disp('1. for Yes');
disp('2. for No');
q = input('');
clc;
while q==1
disp('What is the price of the item?');
x = input('');
disp('What type of item is it?');
disp('1. for Luxury Items');
disp('2. for Food or Medical Items');
disp('3. for All Other Items');
y = input('');
if y==1
z=(x)+(x*0.11);
elseif y==2
z=x;
else
z=(x)+(x*0.07);
end
if q==2
end
end
clc;
disp('The Total Cost of the Item (Dollars):');
disp(z+d);
But the problem is that this funtions keeps looping, I want it to prompt me "Do you have any more items after every item I add. Anything help, I'm totally lost in this loop. Thanks!
0 Commenti
Risposte (1)
Walter Roberson
il 15 Ott 2016
while true
disp('Do you have more items?');
disp('1. for Yes');
disp('2. for No');
q = input('');
if q == 2
break
end
.....
end
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!