C# calculation problem calculating income tax (PAYE)

777 Views Asked by At

I'm experiencing problem while calculating PAYE. Can someone assist me on how I should be approving this.

Here are the percentage and brackets for PAYE.

Upto 24000, 10%  
Between 24001-40667, 15% 
Between 40668-57334, 20%
Above 57334, 25%
There's a relief of 2400.

Here's my code:

double grossIncome=Convert.ToDouble(txtgross.Text):

private double getTax(double gross)
{
if(gross <=24000) return(gross*0.1);
if(gross >=24001 | gross <=40667) return(gross*0.15);
if(gross >=40668 | gross <=57334) return(gross*0.2);
return (57335+(gross*0.25);
}

To calculate PAYE:.

private void btnCalculate_Click(object sender,EventArgs e)
{
PAYE=getTax(grossIncome)-2400;
txtPaye.Text=PAYE.ToString();
}

I'm getting less PAYE value.

1

There are 1 best solutions below

1
zaitsman On

Try this:


double grossIncome=Convert.ToDouble(txtgross.Text):

private double getTax(double gross)
{
    double result = 0;

    if (gross <=24000) {
      return gross*0.1;
    } else {
      result += 2400;
    }

    if (gross >=24001) {
       var firstBase = gross - 24000;
       result += firstBase * 0.15;

       if (gross <= 40667) {
        return result;
       }
    }

    var third = gross - 40667;

    result += third * 0.2;

    if (gross <= 57334) {
       return result;
    }

    var lastbase = gross - 57334;

    result += lastbase * 0.25;

    return result;
}