cash register with tax calculator
7 views (last 30 days)
Show older comments
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
Answers (0)
See Also
Categories
Find more on Function Approximation, Clustering, and Control in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!