cash register with tax calculator

7 views (last 30 days)
fernando piedra
fernando piedra on 26 Aug 2020
Commented: Rik on 27 Aug 2020
so im trying to create a program that enables me to calculate a total tax, however each purchase has a different tax rate and i have to add the respective tax rate to the purchase. so when i create a for loop thing are not adding up
load a02_data.mat
sub_tot = sum(purchases(:,1));
tax = 0;
L = length(purchases(:,1));
for ind = 1:L
if purchases(ind,1) == 0
sub_tot_0 = sum(purchases(ind,1));
tax_tot_0= sub_tot_0 + tax_rate(1)*purchase(ind,1);
elseif purchases(ind,1)== 1
sub_tot_1 = sub_tot + purchases(ind,1);
tax_tot_1 = sub_tot_1 + tax_rates(2)*purchase(ind,1);
elseif purchases(ind,1) == 2
sub_tot_2 = sub_tot + purchases(ind,1);
tax_tot_2 = sub_tot_2 + tax_rates(3)*purchase(ind,1);
end
end
tot = sum([tax_tot_0,tax_tot_1,tax_tot_2]);
disp(sub_tot);
disp(tot);
  4 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 27 Aug 2020
After execute the code, can you show the screnshot of the workspace?
Rik
Rik on 27 Aug 2020
Instead of posting screenshots, post your data and your code. You can attach a mat file with the paperclip icon.
Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!