P: 10

I have been asked to solve this problem:
We want to compute the yearly and monthly rate of taxes to be paid by a person earning a given gross yearly salary, knowing the rates for NI contributions, pension contributions, and income tax. We shall use imaginary figures, not real rates.
The salary is input from the keyboard.
The NI contribution is calculated as 6% of the gross salary.
The pension contribution is calculated as 2% of the gross salary.
The income tax is computed progressively after detracting NI and pension contributions. The taxable amount (after detractions) is divided into bands, each taxed at a different rate as follows:
Gross yearly income: Tax rate:
0  4000 0% on first 4000
4001 – 15000 17% on next 10999
15001 – 30000 25% on next 14999
30001 and above 40% on any remainder
For example, if the gross yearly salary is 32,588, then the yearly contributions are 1955.28 (NI) and 651.76 (pension), and the income tax is applicable to
32588(1955.28+651.76) = 29980.96.
The total yearly income tax is 0+1869.93+3745.49 = 5614.92:
0 on the first 4000 (leaving 25980.96 to tax), plus
17% on the second 10999 = 1869.93 (leaving 14981.96 to tax), plus
25% on the remaining 14981.96 = 3745.49 (as 14981.96 smaller than 14999)
The session must look like this (including the tabular structure and alignment):
Input gross yearly salary: 32,588
Contributions:
Monthly Yearly
NI 162.94 1955.28
Pension 54.31 651.76
Taxable amount after detractions: 29980.96
Tax due 467.91 5614.92
I have done everything except there seems to be a few errors when i'm working out the tax due. Could someone help please!!
Everything is correct before this point, I think i may just have a small syntax error somewhere but can't find the exact solution
This is my tax code: 
if (taxable <= 4000)

{

tax = 0 ;

}

else

{

tax = 0;

taxable = taxable  4000 ;

}

if (taxable <= 15000)

{

tax = taxable*17/100;

}

else

{

tax = tax + (10999*17/100);

taxable = taxable  10999;

}

if (taxable <=30000)

{

tax = tax + taxable*25/100;

}

else

{

tax = tax + (14999*25/100);

taxable = taxable  14999 ;

}

if (taxable >= 30001 )

{

tax = tax + taxable*40/100 ;

}

taxmo = tax/12;

Thanks for any help
 
Share this Question
Expert Mod 2.5K+
P: 4,677

I have been asked to solve this problem:
We want to compute the yearly and monthly rate of taxes to be paid by a person earning a given gross yearly salary, knowing the rates for NI contributions, pension contributions, and income tax. We shall use imaginary figures, not real rates.
The salary is input from the keyboard.
The NI contribution is calculated as 6% of the gross salary.
The pension contribution is calculated as 2% of the gross salary.
The income tax is computed progressively after detracting NI and pension contributions. The taxable amount (after detractions) is divided into bands, each taxed at a different rate as follows:
Gross yearly income: Tax rate:
0  4000 0% on first 4000
4001 – 15000 17% on next 10999
15001 – 30000 25% on next 14999
30001 and above 40% on any remainder
For example, if the gross yearly salary is 32,588, then the yearly contributions are 1955.28 (NI) and 651.76 (pension), and the income tax is applicable to
32588(1955.28+651.76) = 29980.96.
The total yearly income tax is 0+1869.93+3745.49 = 5614.92:
0 on the first 4000 (leaving 25980.96 to tax), plus
17% on the second 10999 = 1869.93 (leaving 14981.96 to tax), plus
25% on the remaining 14981.96 = 3745.49 (as 14981.96 smaller than 14999)
The session must look like this (including the tabular structure and alignment):
Input gross yearly salary: 32,588
Contributions:
Monthly Yearly
NI 162.94 1955.28
Pension 54.31 651.76
Taxable amount after detractions: 29980.96
Tax due 467.91 5614.92
I have done everything except there seems to be a few errors when i'm working out the tax due. Could someone help please!!
Everything is correct before this point, I think i may just have a small syntax error somewhere but can't find the exact solution
This is my tax code: 
if (taxable <= 4000)

{

tax = 0 ;

}

else

{

tax = 0;

taxable = taxable  4000 ;

}

if (taxable <= 15000)

{

tax = taxable*17/100;

}

else

{

tax = tax + (10999*17/100);

taxable = taxable  10999;

}

if (taxable <=30000)

{

tax = tax + taxable*25/100;

}

else

{

tax = tax + (14999*25/100);

taxable = taxable  14999 ;

}

if (taxable >= 30001 )

{

tax = tax + taxable*40/100 ;

}

taxmo = tax/12;

Thanks for any help
I believe your loops are mixed up  for instance, if taxable will enter into the first loop, it will also go through the next two. Was that intentional, or are you looking for a conditional such as this for your following loops: 
if ((taxable > 4000) && (taxable <= 15000))

 
P: 10

If taxable is greater than 4000 then it should go into the next loop.
in the second loop the next 10999 is then taxed at 17%.
If the remainder from the second loop is greater than 15000 then it should go into the next loop.
in the third loop any value up to a maximum of 14999 is then taxed at 25%
If the remainder from the third loop is greater than 30000 then 40% is taxed on the remainder.
Its a bit complicated working through but this is it summed up:
Gross yearly income: Tax rate:
0  4000 0% on first 4000
4001 – 15000 17% on next 10999
15001 – 30000 25% on next 14999
30001 and above 40% on any remainder
Here's an example of what should be produced:
For example, if the gross yearly salary is 32,588, then the yearly contributions are 1955.28 (NI) and 651.76 (pension), and the income tax is applicable to
32588(1955.28+651.76) = 29980.96.
The total yearly income tax is 0+1869.93+3745.49 = 5614.92:
0 on the first 4000 (leaving 25980.96 to tax), plus
17% on the second 10999 = 1869.93 (leaving 14981.96 to tax), plus
25% on the remaining 14981.96 = 3745.49 (as 14981.96 smaller than 14999)
Thanks
 
P: 10

just to clarify, it was intended to pass into the next loop
  Expert Mod 2.5K+
P: 4,677

If taxable is greater than 4000 then it should go into the next loop.
in the second loop the next 10999 is then taxed at 17%.
If the remainder from the second loop is greater than 15000 then it should go into the next loop.
in the third loop any value up to a maximum of 14999 is then taxed at 25%
If the remainder from the third loop is greater than 30000 then 40% is taxed on the remainder.
Its a bit complicated working through but this is it summed up:
Gross yearly income: Tax rate:
0  4000 0% on first 4000
4001 – 15000 17% on next 10999
15001 – 30000 25% on next 14999
30001 and above 40% on any remainder
Here's an example of what should be produced:
For example, if the gross yearly salary is 32,588, then the yearly contributions are 1955.28 (NI) and 651.76 (pension), and the income tax is applicable to
32588(1955.28+651.76) = 29980.96.
The total yearly income tax is 0+1869.93+3745.49 = 5614.92:
0 on the first 4000 (leaving 25980.96 to tax), plus
17% on the second 10999 = 1869.93 (leaving 14981.96 to tax), plus
25% on the remaining 14981.96 = 3745.49 (as 14981.96 smaller than 14999)
Thanks
What is the error you are getting?
 
P: 10

What is the error you are getting?
The values should be 467.91 for monthly tax due and 5614.92
I get 304.12 and 3649.49 Respectively.
i think I may have an error when passing through the loops somewhere which isn't adding certain peices of code or something.
Would u like me to send my entire code?
  Expert Mod 2.5K+
P: 4,677

The values should be 467.91 for monthly tax due and 5614.92
I get 304.12 and 3649.49 Respectively.
i think I may have an error when passing through the loops somewhere which isn't adding certain peices of code or something.
Would u like me to send my entire code?
No, I was just being lazy and trying to spotread it (yeah, I'm definitely not very good at that). I'll put it into a compiler now :)
 
P: 10

No, I was just being lazy and trying to spotread it (yeah, I'm definitely not very good at that). I'll put it into a compiler now :)
would it not be easier to spot the mistakes if u had the entire code?
If you use the value 29980.96 then these are the answer u should get:
monthly tax 467.91 and yearly tax 5614.92
This can be added to the end of the code to clarify the values
taxmo = tax/12;
printf("\nTax due\t\t%7.2f\t\t%7.2f \n",taxmo,tax);
  Expert Mod 5K+
P: 8,916

The problem is in the if statements you treat taxable as if it where not being altered, however each time you calculate the tax for a band you then subtract that bands upper limit from taxable.
Additionally you make no allowance for taxable going negative under this scheme.
I think you will see what I mean if you print tax and taxable just before each if statement.
  Expert Mod 2.5K+
P: 4,677

would it not be easier to spot the mistakes if u had the entire code?
If you use the value 29980.96 then these are the answer u should get:
monthly tax 467.91 and yearly tax 5614.92
This can be added to the end of the code to clarify the values
taxmo = tax/12;
printf("\nTax due\t\t%7.2f\t\t%7.2f \n",taxmo,tax);
Ok, yeah, your loops are confused.
I put in 3999, and i get back that ~139 is owed (per month).
What I was saying was that even when you have something less than the least amount, it will go into the first, and the tax will be zero, but it will also go into the second, and the tax will get set.
Try doing it from highest tax bracket to lowest  reverse the order of them. And just so you know, without a while loop or something else around them, these will all only execute once.
  Expert Mod 2.5K+
P: 4,677

The problem is in the if statements you treat taxable as if it where not being altered, however each time you calculate the tax for a band you then subtract that bands upper limit from taxable.
Additionally you make no allowance for taxable going negative under this scheme.
I think you will see what I mean if you print tax and taxable just before each if statement.
::sigh:: beat to the punch, again.
(But seriously, thanks Banfa! :))
 
P: 10

Ok, yeah, your loops are confused.
I put in 3999, and i get back that ~139 is owed (per month).
What I was saying was that even when you have something less than the least amount, it will go into the first, and the tax will be zero, but it will also go into the second, and the tax will get set.
Try doing it from highest tax bracket to lowest  reverse the order of them. And just so you know, without a while loop or something else around them, these will all only execute once.
Thanks, i'll give that a try.
 
P: 10

The problem is in the if statements you treat taxable as if it where not being altered, however each time you calculate the tax for a band you then subtract that bands upper limit from taxable.
Additionally you make no allowance for taxable going negative under this scheme.
I think you will see what I mean if you print tax and taxable just before each if statement.
Thanks for helping but i still can't see how i am to resolve this problem. I'm not very familiar with programming.
  Expert Mod 2.5K+
P: 4,677

Thanks for helping but i still can't see how i am to resolve this problem. I'm not very familiar with programming.
Can you see the logical progression of how someone under the $4000 bracket will get tax charged to them still  because it still enters the second loop?
 
P: 10

Can you see the logical progression of how someone under the $4000 bracket will get tax charged to them still  because it still enters the second loop?
I can see how it would go through.
Would something like this resolve the problem?
if ((taxable > 4000) && (taxable <= 15000)) {
  Expert Mod 2.5K+
P: 4,677

I can see how it would go through.
Would something like this resolve the problem?
if ((taxable > 4000) && (taxable <= 15000)) {
Well, what I would do is just set that aside for a moment. Open up notepad or get a piece of paper and just sketch out what you want to do, I think (think) it's something like this: 
(pseudocode)

while taxable > 3999

check to see if it's in the highest tax bracket

if so, increment tax by proper amount

and decrease amount by the bracket amount

if not, go to the next lowest bracket

check to see if it's in the second highest bracket

if so, increment tax by proper amount

and decrease by this bracket's ceiling

if not, go to next lowest

// rinse, and repeat

This will keep you going through the code while there is a possible tax bracket you could fall into that will charge you, but stop once you get to that point.
Are you with me so far?
 
P: 10

Well, what I would do is just set that aside for a moment. Open up notepad or get a piece of paper and just sketch out what you want to do, I think (think) it's something like this: 
(pseudocode)

while taxable > 3999

check to see if it's in the highest tax bracket

if so, increment tax by proper amount

and decrease amount by the bracket amount

if not, go to the next lowest bracket

check to see if it's in the second highest bracket

if so, increment tax by proper amount

and decrease by this bracket's ceiling

if not, go to next lowest

// rinse, and repeat

This will keep you going through the code while there is a possible tax bracket you could fall into that will charge you, but stop once you get to that point.
Are you with me so far?
I can't really see how to remove 40% off the remainder if i was to start from the top.
  Expert Mod 2.5K+
P: 4,677

I can't really see how to remove 40% off the remainder if i was to start from the top.
Ok, so if we reverse that  change lowest for highest (and viceversa), you can see that, right?
 
P: 10

Ok, so if we reverse that  change lowest for highest (and viceversa), you can see that, right?
isn't that what my program is already trying to do?
  Expert Mod 2.5K+
P: 4,677

isn't that what my program is already trying to do?
Yeah, but I'm trying to go from algorithm to code  I find it easier, and I'm also a bit distracted at the moment (having the algorithm there would be easier for me to be able to catch up between posts).
  Expert Mod 2.5K+
P: 4,677

Yeah, but I'm trying to go from algorithm to code  I find it easier, and I'm also a bit distracted at the moment (having the algorithm there would be easier for me to be able to catch up between posts).
But anyway, my point was going to be to tighten the conditionals in your if statements, and put them in a loop that will terminate at a certain time  you only want them to be executed one time each, because the main value is recalcualted if it goes into one.
  100+
P: 1,806

Anyone else had trouble with taxes????
  Expert Mod 2.5K+
P: 4,677

Anyone else had trouble with taxes????
I'm having trouble with even just sitting today... It's one of those days...
    Question stats  viewed: 1853
 replies: 22
 date asked: Feb 22 '07
