Trouble with Taxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike25
    New Member
    • Feb 2007
    • 10

    Trouble with Taxes

    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:

    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
    Last edited by sicarie; Feb 22 '07, 04:34 PM. Reason: Added code tags and fixed indentation.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by Mike25
    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:

    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:
    Code:
    if ((taxable > 4000) && (taxable <= 15000))

    Comment

    • Mike25
      New Member
      • Feb 2007
      • 10

      #3
      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

      Comment

      • Mike25
        New Member
        • Feb 2007
        • 10

        #4
        just to clarify, it was intended to pass into the next loop

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by Mike25
          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?

          Comment

          • Mike25
            New Member
            • Feb 2007
            • 10

            #6
            Originally posted by sicarie
            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?

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              Originally posted by Mike25
              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 :)

              Comment

              • Mike25
                New Member
                • Feb 2007
                • 10

                #8
                Originally posted by sicarie
                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 );

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  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.

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    Originally posted by Mike25
                    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.

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #11
                      Originally posted by Banfa
                      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! :))

                      Comment

                      • Mike25
                        New Member
                        • Feb 2007
                        • 10

                        #12
                        Originally posted by sicarie
                        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.

                        Comment

                        • Mike25
                          New Member
                          • Feb 2007
                          • 10

                          #13
                          Originally posted by Banfa
                          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.

                          Comment

                          • sicarie
                            Recognized Expert Specialist
                            • Nov 2006
                            • 4677

                            #14
                            Originally posted by Mike25
                            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?

                            Comment

                            • Mike25
                              New Member
                              • Feb 2007
                              • 10

                              #15
                              Originally posted by sicarie
                              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)) {

                              Comment

                              Working...