Home > Back-end >  cant get tax value even putting in formula
cant get tax value even putting in formula

Time:04-30

Hi I'm very new in c programming, I realized my tax is 0 even I putting in formula, anyone can help to explain why? enter image description here

CodePudding user response:

As shown in your image, the gross pay is $498 and $570 right? If you look at your if-statement at line 29, the gross pay will need to be less than or equal to 300 to return true. In your case, this returns false and your tax calculation is never run.

CodePudding user response:

Incorrect logic.

//Tax
if (pay <=300)
tax = ( pay * 0.15);

Try---

if(pay > 450)
    tax = (pay - 450)*0.25 75;
else if(pay > 300)
    tax = (pay - 300)*0.2 45;
else
    tax = pay*0.15;
  • Related