Hello
I have written a fairly large program, and everything else works fine, but there is one function that has problems. I'll try to show it with the code.
Code:
double ft(double inputGrossPay)
{
double finalFt, firstFt = 0, secondFt = 0, thirdFt = 0;
if (inputGrossPay <= 20000)
{
inputGrossPay = inputGrossPay * 52;
finalFt = ((inputGrossPay * 0.16) / 52 * 1.47);
}
else if (inputGrossPay >= 20000 && inputGrossPay <= 40000)
{
inputGrossPay = inputGrossPay * 52;
secondFt = inputGrossPay - 20000;
firstFt = inputGrossPay - secondFt;
finalFt = ((firstFt * 0.16 + secondFt * 0.23) / 52 * 1.47);
}
else if (inputGrossPay > 40000)
{
inputGrossPay = inputGrossPay * 52;
thirdFt = inputGrossPay - 40000;
secondFt = inputGrossPay - thirdFt;
firstFt = inputGrossPay - secondFt;
finalFt = ((firstFt * 0.16 + secondFt * 0.23 + thirdFt * 0.29) / 52 * 1.47);
}
return finalFt;
}
notice how
Code:
if (inputGrossPay <= 20000)
{
inputGrossPay = inputGrossPay * 52;
finalFt = ((inputGrossPay * 0.16) / 52 * 1.47);
}
is on top of
Code:
else if (inputGrossPay >= 20000 && inputGrossPay <= 40000)
{
inputGrossPay = inputGrossPay * 52;
secondFt = inputGrossPay - 20000;
firstFt = inputGrossPay - secondFt;
finalFt = ((firstFt * 0.16 + secondFt * 0.23) / 52 * 1.47);
}
in this case, when I run the program, some of the answers are correct and some are wrong,
but when I change there order for example if
Code:
if (inputGrossPay >= 20000 && inputGrossPay <= 40000)
{
inputGrossPay = inputGrossPay * 52;
secondFt = inputGrossPay - 20000;
firstFt = inputGrossPay - secondFt;
finalFt = ((firstFt * 0.16 + secondFt * 0.23) / 52 * 1.47);
}
goes on top of
Code:
else if (inputGrossPay <= 20000)
{
inputGrossPay = inputGrossPay * 52;
finalFt = ((inputGrossPay * 0.16) / 52 * 1.47);
}
than the answers that where right get wrong and the wrong ones get right, it seems that only the first if statement runs.
Why is this happening?