Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
James Crowe
James Crowe am 6 Dez. 2017
Kommentiert: Star Strider am 6 Dez. 2017
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

Akzeptierte Antwort

Star Strider
Star Strider am 6 Dez. 2017
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.
  2 Kommentare
James Crowe
James Crowe am 6 Dez. 2017
Ah, got it!
Star Strider
Star Strider am 6 Dez. 2017
Great!
Some things are not always obvious.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by