フィルターのクリア

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

2 ビュー (過去 30 日間)
James Crowe
James Crowe 2017 年 12 月 6 日
コメント済み: Star Strider 2017 年 12 月 6 日
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.
  2 件のコメント
James Crowe
James Crowe 2017 年 12 月 6 日
Ah, got it!
Star Strider
Star Strider 2017 年 12 月 6 日
Great!
Some things are not always obvious.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by