When the button is clicked the desired calculations are not been calculated.
After the Tax paid variable eis entered in the text box, no further calculation taking place.
In the result textbox getting the same data as eneterd in the Tax paid Text box.Can anyone tell wat is the error..
The highlighted statement is not been working.

protected void Button1_Click(object sender, EventArgs e)
    {
        double excesstaxpaid = 0;
        int option;
        option = RadioButtonList1.SelectedIndex;
        double annualincome;
        double taxpaid;
        double taxpayable;
        double actualincome;

        annualincome = Convert.ToInt32(TextBox1.Text);
        taxpaid = Convert.ToInt32(TextBox2.Text);

        switch (option)
        {
            case 1:
                {
                    if (annualincome > 34800)
                    {
                        actualincome = annualincome - 6035;
                        taxpayable = 20 / 100 * actualincome;
                        [COLOR="Red"]excesstaxpaid = taxpaid - taxpayable;[/COLOR]                    }
                    else
                    {
                        actualincome = annualincome - 6035;
                        taxpayable = 40 / 100 * actualincome;
                        [COLOR="red"]excesstaxpaid = taxpaid - taxpayable;[/COLOR]                    }
                }
                break;
            case 2:
                {
                    if (annualincome > 37400)
                    {
                        actualincome = annualincome - 6475;
                        taxpayable = 20 / 100 * actualincome;
                        [COLOR="red"]excesstaxpaid = taxpaid - taxpayable;[/COLOR]                    }
                    else
                    {
                        actualincome = annualincome - 6475;
                        taxpayable = 40 / 100 * actualincome;
                        [COLOR="red"]excesstaxpaid = taxpaid - taxpayable;[/COLOR]                    }
                }
                break;
            case 3:
                {
                    if (annualincome > 37400)
                    {
                        actualincome = annualincome - 6475;
                        taxpayable = 20 / 100 * actualincome;
                       [COLOR="red"] excesstaxpaid = taxpaid - taxpayable;[/COLOR]                    }
                    else
                    {
                        actualincome = annualincome - 6475;
                        taxpayable = 40 / 100 * actualincome;
                        [COLOR="red"]excesstaxpaid = taxpaid - taxpayable;[/COLOR]
                    }

                }

                break;
Label1.Text = excesstaxpaid.ToString();

taxpayable = 20 / 100 * actualincome;

The result of this is zero. Always. The same with all your other calculations like this. 20 / 100 is done with integer division. 20 / 100 = 0, it's then converted to a double and multiplied by actualincome. 0 times anything is zero.

Change the values to 20.0 / 100.0 (and 40.0 / 100.0).

Im getting negative output !!

And? Just means taxpaid is less than taxpayable.

Simple, depending on the year selected, there is a constant subtracted from the annual income.Then the tax to be paid is calculated from that difference according to 20% of the actual income.Then excess tax paid is the difference of actual tax to be paid and excess tax paid.Hope not too confusing.

For eg: x is income
        y is tax paid { Input frm users}
a = x - constant
 z = 20% of a
 excesstaxpaid = taxpaid -z
result is excesstaxpaid..

I understand the math, but it seems you don't. What values are you placing in the various text boxes. Once we know that we can step through the program and see what it is doing.

There r just 2 textboxes, where the user inputs Annaul Income and Tax Paid..

And what values did you put in them, what values do you expect to come out?

Annual Income = 25000
Tax PAid = 5000
Excess Tax PAid = 917.1{Expected Output} but instead Im getting output as 5000
only the statement highlighted is not been executed, if that statement works then it shud b fine ,

Did you change your code as I mentioned above? Which option is selected in the radio button group?

First Radio Button
Income : 25000
Tax Paid :5000
Desired Output: 1207
Actual Output: 5000
I did try as you mentioned with the above code I got this result: -2586

Here is the relevant code, with the changes I told you to make:

case 1: {
    if (annualincome > 34800) {
        actualincome = annualincome - 6035;
        taxpayable = 20.0 / 100.0 * actualincome;
        excesstaxpaid = taxpaid - taxpayable;
    } else {
        actualincome = annualincome - 6035;
        taxpayable = 40.0 / 100.0 * actualincome;
        excesstaxpaid = taxpaid - taxpayable; }
    }
    break;
}

Annualincome = 25000
taxpaid = 5000

Now let's go through the code and see what we get:
Line 2 asks "is annual income > 34800" and the answer is "no" so we go to the else part of the problem (line 7)
actualincome = anualincome - 6035 = 25000 - 6035 = 18965
taxpayable = 40.0 / 100.0 * actualincome = 40.0 / 100.0 * 18965 = 0.4 * 18965 = 7586
excesstaxpaid = taxpaid - taxpayable = 5000 - 7586 = -2586

Amazing, the exact answer you got. Do you see your error yet?

I give up, Im not able to find out the error :(
I tried my best, pls help me...

You are charging people who make less than 34800 the 40% tax rate. You want to charge them the 20% tax rate. Change the '>' signs to '<='.

:( But now problem with the else code, if the annual income > 34800, then the result is negative.
Income : 36000
Tax Paid: 8000
Excess Tax PAid = 2007 {Desired Output}
Actual Output = -3986

40% of (36000-6035) = 11986

8000 - 11986 = -3986

Either your tax rate isn't what you were told or the answer you expect is wrong. The code is doing it's math correctly.

Just FYI, the value you desire is a 20% tax rate.

But thanq so much for ur replies ...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.