By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,407 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,407 IT Pros & Developers. It's quick & easy.

Trouble with Taxes

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:

Expand|Select|Wrap|Line Numbers
  1.    if (taxable <= 4000) 
  2.    {
  3.        tax = 0 ;
  4.    }
  5.    else
  6.    {
  7.        tax = 0;
  8.        taxable = taxable - 4000 ;
  9.    }
  10.    if (taxable <= 15000) 
  11.    {
  12.       tax = taxable*17/100;
  13.    }
  14.    else
  15.    {
  16.        tax = tax + (10999*17/100);
  17.       taxable = taxable - 10999;
  18.    }
  19.    if (taxable <=30000) 
  20.    {
  21.       tax = tax + taxable*25/100;
  22.    }
  23.    else
  24.    {
  25.       tax = tax + (14999*25/100);
  26.       taxable = taxable - 14999 ;
  27.    }
  28.    if (taxable >= 30001 )
  29.    {
  30.       tax = tax + taxable*40/100 ;
  31.    }
  32.    taxmo = tax/12;
  33.  
Thanks for any help
Feb 22 '07 #1
Share this Question
Share on Google+
22 Replies


sicarie
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:

Expand|Select|Wrap|Line Numbers
  1.    if (taxable <= 4000) 
  2.    {
  3.        tax = 0 ;
  4.    }
  5.    else
  6.    {
  7.        tax = 0;
  8.        taxable = taxable - 4000 ;
  9.    }
  10.    if (taxable <= 15000) 
  11.    {
  12.       tax = taxable*17/100;
  13.    }
  14.    else
  15.    {
  16.        tax = tax + (10999*17/100);
  17.       taxable = taxable - 10999;
  18.    }
  19.    if (taxable <=30000) 
  20.    {
  21.       tax = tax + taxable*25/100;
  22.    }
  23.    else
  24.    {
  25.       tax = tax + (14999*25/100);
  26.       taxable = taxable - 14999 ;
  27.    }
  28.    if (taxable >= 30001 )
  29.    {
  30.       tax = tax + taxable*40/100 ;
  31.    }
  32.    taxmo = tax/12;
  33.  
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:
Expand|Select|Wrap|Line Numbers
  1. if ((taxable > 4000) && (taxable <= 15000))
  2.  
Feb 22 '07 #2

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
Feb 22 '07 #3

P: 10
just to clarify, it was intended to pass into the next loop
Feb 22 '07 #4

sicarie
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?
Feb 22 '07 #5

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?
Feb 22 '07 #6

sicarie
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 spot-read it (yeah, I'm definitely not very good at that). I'll put it into a compiler now :)
Feb 22 '07 #7

P: 10
No, I was just being lazy and trying to spot-read 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);
Feb 22 '07 #8

Banfa
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.
Feb 22 '07 #9

sicarie
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.
Feb 22 '07 #10

sicarie
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! :))
Feb 22 '07 #11

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.
Feb 22 '07 #12

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.
Feb 22 '07 #13

sicarie
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?
Feb 22 '07 #14

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)) {
Feb 22 '07 #15

sicarie
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:

Expand|Select|Wrap|Line Numbers
  1. (pseudocode)
  2. while taxable > 3999
  3.     check to see if it's in the highest tax bracket
  4.     if so, increment tax by proper amount
  5.         and decrease amount by the bracket amount
  6.     if not, go to the next lowest bracket
  7.     check to see if it's in the second highest bracket
  8.     if so, increment tax by proper amount
  9.         and decrease by this bracket's ceiling
  10.     if not, go to next lowest
  11.     // rinse, and repeat
  12.  
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?
Feb 22 '07 #16

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:

Expand|Select|Wrap|Line Numbers
  1. (pseudocode)
  2. while taxable > 3999
  3.     check to see if it's in the highest tax bracket
  4.     if so, increment tax by proper amount
  5.         and decrease amount by the bracket amount
  6.     if not, go to the next lowest bracket
  7.     check to see if it's in the second highest bracket
  8.     if so, increment tax by proper amount
  9.         and decrease by this bracket's ceiling
  10.     if not, go to next lowest
  11.     // rinse, and repeat
  12.  
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.
Feb 22 '07 #17

sicarie
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 vice-versa), you can see that, right?
Feb 22 '07 #18

P: 10
Ok, so if we reverse that - change lowest for highest (and vice-versa), you can see that, right?
isn't that what my program is already trying to do?
Feb 22 '07 #19

sicarie
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).
Feb 22 '07 #20

sicarie
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.
Feb 22 '07 #21

DeMan
100+
P: 1,806
Anyone else had trouble with taxes????
Feb 22 '07 #22

sicarie
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...
Feb 22 '07 #23

Post your reply

Sign in to post your reply or Sign up for a free account.