How would I output the 'ans' as 'TaxPayable' instead?

2 次查看(过去 30 天)
Hi, how would I output the 'ans' as 'TaxPayable' instead. I'm also aware that this code is probably very inefficient, so any suggestions wouldn't go a miss. How would I also get a '£' symbol in front of the value after 'ans'? Thank you!
function [TaxPayable] = TaxCalculator(AnnualSalary, Year)
%The first if statement looks if the input Year is valid, if not it
%displays an error message.
if Year == 2015 || 2016 || 2017 %If the input year is valid, the function will use the correct year
if Year == 2015
if AnnualSalary >= 43352 %The function then finds the correct salary range
TaxPayable = 6690.4 + (AnnualSalary - 43352)*0.4; %Once in the correct salary range it uses a
elseif AnnualSalary>=11000 %predetermined figure plus the amount of money
TaxPayable = 220 + (AnnualSalary-11000)*0.2; %over the tax bounds.
else
TaxPayable = 0.02*AnnualSalary;
end
elseif Year == 2016
if AnnualSalary >= 43352
TaxPayable = 5127.8 + (AnnualSalary - 43352)*0.45;
elseif AnnualSalary>=11000
TaxPayable = 275 + (AnnualSalary-11000)*0.15;
else
TaxPayable = 0.025*AnnualSalary;
end
else
if AnnualSalary >= 43352
TaxPayable = 8088 + (AnnualSalary - 43352)*0.48;
elseif AnnualSalary>=11000
TaxPayable =(AnnualSalary-11000)*0.25;
else
TaxPayable = 0*AnnualSalary;
end
end
else
disp('Error, invalid year')
end
end

采纳的回答

Star Strider
Star Strider 2017-12-6
I get the impression that you are calling it as:
TaxCalculator(AnnualSalary, Year)
without an output variable. Calling it instead as:
TaxPayable = TaxCalculator(AnnualSalary, Year)
will probably do what you want.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by