Hi,
I'm new in this forum and c language, need somebody to correct my programme as below:

Question
Design and implement an interactive program that reads your yearly gross salary and computes and prints your net monthly take home income. Assume that your yearly gross salary is greater than RM 50,000 but less than RM80,000, and the following deduction are applicable:

a) Federal income tax : RM 5100.00 plus 28% of gross income over RM 34,000.
b) State tax : 9% of gross income.
c) City tax : 1.75% of gross income.
d) Social security : 8.75% of the first RM 45,000 of gross income.

``````#include <stdio.h>
main ()
{
int yearlygross;
int fedtax;
float statetax;
float citytax;
long socialsec;
float totaldeduction;
long netincome;
printf("Enter your yearly gross salary   :");
scanf ("%d",&yearlygross);
fedtax = 5100+(0.28*yearlygross);
statetax = 0.09*yearlygross;
citytax = 0.0175*yearlygross;
socialsec = 0.0875*45000;
totaldeduction = fedtax+statetax+citytax+socialsec;
netincome = yearlygross-totaldeduction/12;
printf("Net monthly take home income is %dn", netincome);
return 0;
}
``````

Let say the yearly gross is 60,000, the monthly net income should 2,309.30 after deduction all those taxes.
my calculation as below:
fed tax = 5100 + 16800 = 21900
statetax = 5400
citytax = 1050
social security = 3937.5
total = 32287.5 - 60000 = 27712.5 divide by 12 mths = 2309.30.

Not sure whether this is correct, but I can't get the correct answer
I guess I wrongly use integral data types.

Edited by Dani: Formatting fixed

4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by mitrmkar

netincome = yearlygross-totaldeduction/12;

that should be

netincome=(yearlygross-totaldeduction)/12;

one more thing

if you were asked to validate the input yearly gross
have something like this:

``````do{
printf("Enter your yearly gross salary :");
scanf ("%d",&yearlygross);
}while (yearlygross<50000||yearlygross>80000);``````

//edit: sorry for the double post.

//edit: sorry for the double post.

If you don't want want to double post, you can edit your first post. But double posting is not a problem if you have additional information. It's bumping we frown on.

>> you can edit your first post.
It seems that once posted, a post remains editable for some short period of time and then enters a non-editable mode. Is there any way, for one to edit one's own post regardless of how long it has been on the forum?

By the way, what is 'bumping' in this context?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.