# Thread: Help with my program

1. ## Help with my program

#include <stdio.h>

int main()
{
float overtime_week_day=14,overtime_weekend=5,total_over _time;
float overtime_weekendpay,overtime_week_daypay,standard_ pay, normal_pay;
float over_pay, new_pay1, new_pay2;
float tax1, tax2, tax3,tax;

standard_pay=19.73*35;

total_over_time=overtime_weekend+overtime_week_day ;
overtime_weekendpay=overtime_weekend*(1.25*19.73);
overtime_week_daypay=overtime_week_day*(1.5*19.73) ;

over_pay=overtime_weekendpay+overtime_week_daypay;
normal_pay=standard_pay+over_pay;

{
if(normal_pay>=200)
{
tax1=(30/100)*normal_pay;
new_pay1=normal_pay-tax1;
}
else if(new_pay1>=300)
{
tax2=(40/100)*normal_pay;
new_pay2=new_pay1-tax2;
}

else if(new_pay2>=0)
{
tax3=(50/100)*new_pay2;
}
tax=tax1+tax2+tax3;
}
printf("\nThe normal week pay is %f, the overtime pay is %f, the tax deduction is %2f\n",normal_pay,over_pay,tax);

return 0;
}

Output:
The normal week pay is 1228.192383, the overtime pay is 537.642456, the tax deduction is -214748352.0000........

i dunno wots wrong with my program i fink its the if else can some help me so that it returns the correct value for "tax deduction" safe...

2. for one, your variables "total_over time" and "standard_ pay" have spaces in them. what is the correct value for "tax deduction"?

4. I fix the space....I dont know wot the actual value for the tax but the question says.... Income tax is paid at a rate of 30% on the £200 of a weeks pay, 40% on the next 300 and 50% on the remainder. thats where i thought of constructing the if else

if(normal_pay>=200)
{
tax1=(30/100)*normal_pay;
new_pay1=(normal_pay-tax1);
}
else if(new_pay1>=300)
{
tax2=(40/100)*normal_pay;
new_pay2=(new_pay1-tax2);
}

else if(new_pay2>=0)
{
tax3=(50/100)*new_pay2;
}

6. this might help:
Code:
```#include <stdio.h>

int main()
{
float overtime_week_day=14,overtime_weekend=5,total_overtime;
float overtime_weekendpay,overtime_week_daypay,standard_pay, normal_pay;
float over_pay, new_pay1, new_pay2;
float tax1, tax2, tax3,tax;

standard_pay=19.73*35;

total_overtime=overtime_weekend+overtime_week_day;
overtime_weekendpay=overtime_weekend*(1.25*19.73);
overtime_week_daypay=overtime_week_day*(1.5*19.73) ;

over_pay=overtime_weekendpay+overtime_week_daypay;
normal_pay=standard_pay+over_pay;

{
if(normal_pay>=200)
{
tax1=(30/100)*normal_pay;
printf("tax1 = %f\n", tax1);
new_pay1=normal_pay-tax1;
printf("new_pay1 = %f\n", new_pay1);
}
else if(new_pay1>=300)
{
tax2=(40/100)*normal_pay;
printf("tax2 = %f\n", tax2);
new_pay2=new_pay1-tax2;
printf("new_pay2 = %f\n", new_pay2);
}

else if(new_pay2>=0)
{
tax3=(50/100)*new_pay2;
printf("tax3 = %f\n", tax3);
}
tax=tax1+tax2+tax3;
printf("tax = %f\n", tax);
}
printf("\nThe normal week pay is %f, the overtime pay is %f, the tax deduction is %2f\n",normal_pay,over_pay,tax);

return 0;
}```

7. i now see that the code i posted also has spaces in those two variables. i wonder if something's wrong with the forum.

8. Well if you just copy/paste from the forum, then your post isn't much better than before.
But if you copy/paste directly from your source code editor directly into code tags, the results are usually pretty good.

9. Code:
```         tax1=(30/100)*normal_pay;
tax2=(40/100)*normal_pay;
tax3=(50/100)*new_pay2;```
Doing integer math means these will all be zero.
Code:
```         tax1=(30.0F/100)*normal_pay;
tax2=(40.0F/100)*normal_pay;
tax3=(50.0F/100)*new_pay2;```

10. Originally Posted by Salem
Well if you just copy/paste from the forum, then your post isn't much better than before.
But if you copy/paste directly from your source code editor directly into code tags, the results are usually pretty good.
i copied from the board, pasted it in emacs, corrected the spacing errors, ... copied it from emacs, pasted it to the board, and the spacing errors are back after it is submitted. try it.

11. > float overtime_weekendpay,overtime_week_daypay,standard_ pay, normal_pay;
Then it's perhaps the total lack of space everywhere else in the line
Code:
`float overtime_weekendpay, overtime_week_daypay, standard_pay, normal_pay;`

12. seems like a bug in the forum software. this works:
Code:
` float overtime_week_day=14, overtime_weekend=5, total_over_time;`
but this doesn't:
Code:
` float overtime_week_day=14,overtime_weekend=5,total_over_time;`

13. are you using tabs or spaces? Are you using the quick reply or the advanced text editor? What happens when you copy from emacs and paste into another text editor?

14. Originally Posted by Thantos
are you using tabs or spaces? Are you using the quick reply or the advanced text editor? What happens when you copy from emacs and paste into another text editor?
spaces. advanced text editor. it's the same.

15. >spaces. advanced text editor. it's the same.
Try using the standard editor, it's much more predictable.