Help with script w/ more than one equation?

23 次查看(过去 30 天)
TaxableIncome=input('Please provide taxable income in Australian Dollars:');
IncomeTax=0;
MedicareLevy=(TaxableIncome*0.015);
TotalTax=IncomeTax + MedicareLevy;
if IncomeTax>0 && MedicareLevy>0
end
if TaxableIncome>=0
end
if TaxableIncome>=0 && TaxableIncome<=6000
elseif TaxableIncome>6000&& TaxableIncome<=20000
    IncomeTax=0.17*(TaxableIncome-6000);
elseif TaxableIncome>20000 && TaxableIncome<=50000
    IncomeTax=2380+0.30*(TaxableIncome-20000);
elseif TaxableIncome>50000 && TaxableIncome<=60000
    IncomeTax=11380+0.42*(TaxableIncome-50000);
elseif TaxableIncome>60000
    IncomeTax=15580+0.47*(TaxableIncome-60000);
end
fprintf('Income Tax is %f.\n', IncomeTax);
fprintf('Medicare Levy is %f.\n', MedicareLevy);
fprintf('Total Tax is %f.\n', TotalTax);

This is the question I am answering but I am not sure why my Total Tax isnt adding the Medicare Levy and the Income Tax:

        3.11 The author of this book now lives in Australia. Australia is a great place
       to live, but it is also a land of high taxes. In 2002, individual citizens and
       residents of Australia paid the following income taxes:
               Taxable Income (in A$)       Tax on This Income
               $0–$6,000                    None
               $6,001–$20,000               17¢ for each $1 over $6,000
               $20,001–$50,000              $2,380 plus 30¢ for each $1 over $20,000
               $50,001–$60,000              $11,380 plus 42¢ for each $1 over $50,000
               Over $60,000                 $15,580 plus 47¢ for each $1 over $60,000
         In addition, a flat 1.5% Medicare levy is charged on all income. Write a
         program to calculate how much income tax a person will owe based on this information. The program should accept a total income figure from the user and calculate the income tax, Medicare levy, and total tax payable by the individual.| * 
  *                    
  1 个评论
Pam
Pam 2014-11-23
编辑:Star Strider 2014-11-23

This is what my command window shows:

>> Tax
Please provide taxable income in Australian Dollars:6001
Income Tax is 0.170000.
Medicare Levy is 90.015000.
Total Tax is 90.015000.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2014-11-23
编辑:Star Strider 2014-11-23
Computers do things in the order you tell them to:
TaxableIncome=input('Please provide taxable income in Australian Dollars:');
IncomeTax=0;
MedicareLevy=(TaxableIncome*0.015);
% TotalTax=IncomeTax + MedicareLevy; <== PUT THIS LINE AFTER THE INCOME TAX CALCULATION
if IncomeTax>0 && MedicareLevy>0
end
if TaxableIncome>=0
end
if TaxableIncome>=0 && TaxableIncome<=6000
elseif TaxableIncome>6000&& TaxableIncome<=20000
IncomeTax=0.17*(TaxableIncome-6000);
elseif TaxableIncome>20000 && TaxableIncome<=50000
IncomeTax=2380+0.30*(TaxableIncome-20000);
elseif TaxableIncome>50000 && TaxableIncome<=60000
IncomeTax=11380+0.42*(TaxableIncome-50000);
elseif TaxableIncome>60000
IncomeTax=15580+0.47*(TaxableIncome-60000);
end
TotalTax=IncomeTax + MedicareLevy;
fprintf('Income Tax is %f.\n', IncomeTax);
fprintf('Medicare Levy is %f.\n', MedicareLevy);
fprintf('Total Tax is %f.\n', TotalTax);
This worked when I ran it.
P.S. — Apologise for the delay, but it’s yesterday here!
  2 个评论
Pam
Pam 2014-11-23
thank you and its fine I also figured it out this point but I do appreciate the help. I did it a bit differently but it also worked.
Star Strider
Star Strider 2014-11-23
My pleasure!
If it gives you the correct answer, it works.

请先登录,再进行评论。

更多回答(1 个)

John wick
John wick 2021-2-9
I know this is really old, but I have the same assignmet and I was having trouble with the first fprintf function. Hope this helps out another student in the far future
clear
clc
disp('This program calculates the taxes for Australia')
personincome=input('Enter the persons total income:');
tax=0;
MedLev=.015*personincome;
if (personincome<=6000)
tax=0;
elseif 6001>=20000
tax=.75*(personincome-6000);
elseif 20001<=50000
tax=2380+.30*(personincome-20000);
elseif 50001<=60000
11380+.42*(personincome-50000);
else
tax=15580+.47*(personincome-60000);
end
Tottx=personincome+MedLev;
fprintf('For an income of %g the taxes are:\n',personincome);
fprintf('Medicare Levy:%.0f\n',tax);
fprintf('Income Tax:%.0f\n',MedLev);
fprintf('Total Tax:%.0f\n',Tottx);

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by