0

Write code that will:

• Ask the user for their tax code (A or B) and annual salary

• Display the tax the person has to pay for the year. People on tax code A have to pay 25% of their salary in tax, those on tax code B must pay 30% if their salary is $45,000 or less, 33% otherwise.

Example:

What is your tax code? A
What is your annual salary? 42560
Tax due $10,640

so my question is how do i do this in Microsoft Visual studio?
I appreciate all the help and comments :)

ChrisWue
  • 18,612
  • 4
  • 58
  • 83
  • 3
    I guess this is homework. How about you post what you have already? – ChrisWue Mar 25 '11 at 06:09
  • 1
    Hmmm... How much are you willing to pay if I complete your homework? :) – Mayank Mar 25 '11 at 06:10
  • 1
    @Mayank: perhaps he'll arrange for you to be eligible for tax code A? – Michael Burr Mar 25 '11 at 06:14
  • So someone with tax code B earning $45,000, pays $13,500, but if they earn one extra dollar, they then pay $14,850? Ouch! – dwarring Mar 25 '11 at 06:17
  • did it ever come to your mind that you only learn something when you at least try to solve it on your own? You did not even told us where you have a problem, just posted this homework question and asked the community to solve it for you. – Doc Brown Mar 25 '11 at 06:50

3 Answers3

1

Start a console project.

Print out with System.Console.Write ("question?"); or System.Console.WriteLine("question?");

Get input with string input = Console.ReadLine();

Convert to required data type using functions like int salary = int.Parse(input)

Process according to the requirement. You will mostly use if to determine which rate to use.

Remember to repeat the question if the input is not correct; eg: not a number, not A or B.

Fun Mun Pieng
  • 6,751
  • 3
  • 28
  • 30
1

long amount = [get amount];

string taxCode = [get code];

decimal tax =0;

if (taxCode == "A" && amount <= 45000)
   tax = 0.25M * amount;
else if (taxCode == "B" && amount <= 45000)
   tax = .3M * amount;
else
   tax = .33M * amount;

This should do the trick

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • 2
    Please don't recommend using `double` for monetary values. `decimal` is far more appropriate here. – Jon Skeet Mar 25 '11 at 06:22
  • @Jon: Changed to decimal, hope this is good enough ,For those who read later [see this](http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when) – V4Vendetta Mar 25 '11 at 06:30
0

This should get you started:

float rate;

if(ddl_Code.SelectedValue ==  "A")
{
   rate = .25F;
}
else if(ddl_Code.SelectedValue ==  "B" && Convert.ToDecimal(tb_Salary.Text) <= 45000)
{
   rate = .3F;
}
else
{
   rate = .33F;
}

tb_TaxDue.Text = Convert.ToDecimal(tb_Salary.Text) * rate;

This assumes you have a drop down list for Tax Code and two text boxes for Taxes due and salary.

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486