Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
James Crowe
James Crowe el 6 de Dic. de 2017
Comentada: Star Strider el 6 de Dic. de 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

Respuesta aceptada

Star Strider
Star Strider el 6 de Dic. de 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 comentarios
James Crowe
James Crowe el 6 de Dic. de 2017
Ah, got it!
Star Strider
Star Strider el 6 de Dic. de 2017
Great!
Some things are not always obvious.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by