I am writing a method to calculate income tax based on gross pay and number of dependents. When I try and compile the following code, my dTaxOnIncome variable is getting not initialized.
public static double incomeTax(double gross, int dependents)
{
double dTaxOnIncome; // holds the calculated income tax.
if(gross >= 10000 && dependents == 0)
{
dTaxOnIncome = gross * .25;
}
else
{
if((gross >= 10000) && ((dependents >= 1 && dependents <= 4)))
{
if(dependents == 1)
{
dTaxOnIncome = gross * .24;
}
else
{
if(dependents == 2)
{
dTaxOnIncome = gross * .23;
}
else
{
if(dependents == 3)
{
dTaxOnIncome = gross * .22;
}
else
{
if(dependents == 4)
{
dTaxOnIncome = gross * .21;
}
else
{
if(dependents == 5)
{
dTaxOnIncome = gross * .205;
}
else
{
if(dependents == 6)
{
dTaxOnIncome = gross * .20;
}
else
{
if(dependents > 6)
{
dTaxOnIncome = gross * .18;
}
else
{
}
}
}
}
}
}
}
}
}
return dTaxOnIncome;
}// end incomeTax (double, int)
I know that I could use if else statements, but I have tried this problem multiple ways and this seemed to be the most straight forward.
Aucun commentaire:
Enregistrer un commentaire