salary calculation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • james121285
    New Member
    • Feb 2007
    • 18

    salary calculation

    This is to calculate an employees tax and pension.
    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



    can someone check this, this is my first attempt at this program, and its came straight from paper. Thanks for your help.

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main (void)
    
    {
    int salary, NI, pension, part1, part2, part3, part3, part4, part5, part6;
    int part7, part8, part9, part10, part11, part12, part13, part14, part15;
    
    printf(''enter your yearly salary'');
    scanf(''%d'',&salary);
    
    NI= (salary/100)*6;
    pension=(salary/)*2;
    
           If (salary<4000);
     {
          then
          printf(''your yearly salary is'', salary);
          printf(''your yearly tax is'', NI);
          printf(''your yearly pension is'',pension);
    }
    
         If (4001<salary<15000);
    {
         part1= salary-4000;
         part2= (part1/)*17;
         part3=NI + part2;
    then
        printf(''your salary is'', salary);
        printf(''your yearly tax is'', part3);
        printf(''your yearly pension is'', pension);
    }
    
        If (15001salary30000);
    {
       part4= salary-4000;
       part5= part4-11000;
       part6= (part4/100)*17;
       part7= (part5/100)*25;
       part8= NI+ part6+ part7;
    then
       printf(''your salary is'', salary);
       printf(''your yearly tax is'', part8);
       printf(your yearly pension is'', pension);
    }
    
       else (salary>30001);
    {
       part9= salary-4000;
       part10= part9-11000;
       part11= part10- 15000;
    
       part12= (part9/100)*17;
       part13=(part10/100)*25;
       part14=(part11/100)*40;
    
       part15= NI+ part12+ part13+ part14;
    
    then
      printf(''your salary is'', salary);
      printf(''your yearly tax  is'', part15);
      printf(''your yearly pension is'', pension);
    
    }
    
    }
    Last edited by sicarie; Feb 15 '07, 10:04 PM. Reason: Added code tags.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    james-

    A few notes, just to start out with (i'm not compiling it yet).

    1) int main (void) {
    The void is unnecessary - you can use 'int main()' or 'void main()'. With int main you need to put 'return 0;' at the end of your program, to show the compiler that it completed successfully. There is no such test with void main, but it is generally pretty apparent when it didn't....

    2) you declare variables parts1-15. You print out part15. For your sake, it is considered good practice to give descriptive names (like 'salary') to keep track of what does what. You can also use (if you like part15) things like 'part15 = part15 * 1.5;' (just an example, I'm not sure if you actually do or not) BUT the equation is carried out from right to left - so the value that is in part15 is multiplied by 1.5, and then assigned back to part15. This means you can use it over again.

    3) If (salary < 4000). All C/C++ keywords are lowercase - if (salary < 4000)

    4) pension = (salary / ) * 2;
    You don't divide salary by anything, so I'm pretty sure it would cause an error (or did you want to divide by two?).

    5) Not sure if you meant to do this or not, but you use printf( ' ' your salary is ' ' //...
    There is a difference between two apostrophes ' ' and a pair of quotes " in C/C++, just make sure you're typing in the correct one (as you said, this came from paper, and a teacher would not know the difference, there it is symantically correct).

    Comment

    • james121285
      New Member
      • Feb 2007
      • 18

      #3
      I have made a few changes, but the program is running all the IF statements and printing all the answers. How do I stop this from happening. Thanks for your help




      Code:
      #include <stdio.h>
      #include <math.h>
      
      int main ()
      
      {
      int salary, NI, pension, part1, part2, part3, part4, part5, part6;
      int part7, part8, part9, part10, part11, part12, part13, part14, part15;
      
      printf("enter your yearly salary");
      scanf("%d",&salary);
      
      NI= (salary/100)*6;
      pension=(salary/100)*2;
      
             if (salary<4000);
       {
      
            printf("your yearly salary is %d", salary);
            printf("your yearly tax is %d", NI);
            printf("your yearly pension is %d",pension);
      }
      
           if (4001<salary<15000);
      {
           part1= salary-4000;
           part2= (part1/100)*17;
           part3=NI + part2;
      
          printf("your salary is %d", salary);
          printf("your yearly tax is %d", part3);
          printf("your yearly pension is %d", pension);
      }
      
          if (15001<salary<30000);
      {
         part4= salary-4000;
         part5= part4-11000;
         part6= (part4/100)*17;
         part7= (part5/100)*25;
         part8= NI+ part6+ part7;
      
         printf("your salary is %d", salary);
         printf("your yearly tax is %d", part8);
         printf("your yearly pension is %d", pension);
      }
      
         if (salary>30001);
      {
         part9= salary-4000;
         part10= part9-11000;
         part11= part10- 15000;
      
         part12= (part9/100)*17;
         part13=(part10/100)*25;
         part14=(part11/100)*40;
      
         part15= NI+ part12+ part13+ part14;
      
      
        printf("your salary is %d", salary);
        printf("your yearly tax  is %d", part15);
        printf("your yearly pension is %d", pension);
      
      }
       return 0;
      
      
      }

      Comment

      • rajesh6695
        New Member
        • Oct 2006
        • 96

        #4
        Try this code....

        Actually In the IF stmt you had entered ; which will terminate the that statment even the condition fails or true the next line will execute....
        So i removed the ; from all if stmts...
        and also check the condition of all IF stmts.....


        Code:
        #include <stdio.h>
        #include <math.h>
        
        int main ()
        
        {
        int salary, NI, pension, part1, part2, part3, part4, part5, part6;
        int part7, part8, part9, part10, part11, part12, part13, part14, part15;
        
        printf("enter your yearly salary");
        scanf("%d",&salary);
        
        NI= (salary/100)*6;
        pension=(salary/100)*2;
        
        if (salary<=4000)
        {
        	printf("your yearly salary is %d\n", salary);
        	printf("your yearly tax is %d\n", NI);
        	printf("your yearly pension is %d\n\n",pension);
        }
        
        if ((salary >= 4001)&&(salary<15000))
        {
        	part1= salary-4000;
        	part2= (part1/100)*17;
        	part3=NI + part2;
        
        	printf("your salary is %d\n", salary);
        	printf("your yearly tax is %d\n", part3);
        	printf("your yearly pension is %d\n\n", pension);
        }
        
        if ((salary >= 15001)&&(salary<=30000))
        {
        	part4= salary-4000;
        	part5= part4-11000;
        	part6= (part4/100)*17;
        	part7= (part5/100)*25;
        	part8= NI+ part6+ part7;
        
        	printf("your salary is %d\n", salary);
        	printf("your yearly tax is %d\n", part8);
        	printf("your yearly pension is %d\n\n", pension);
        }
        
        if (salary>=30001)
        {
        	part9= salary-4000;
        	part10= part9-11000;
        	part11= part10- 15000;
        	
        	part12= (part9/100)*17;
        	part13=(part10/100)*25;
        	part14=(part11/100)*40;
        	
        	part15= NI+ part12+ part13+ part14;
        	
        	
        	printf("your salary is %d\n", salary);
        	printf("your yearly tax is %d\n", part15);
        	printf("your yearly pension is %d\n\n", pension);
        	
        }
        return 0;
        
        
        }

        Comment

        • james121285
          New Member
          • Feb 2007
          • 18

          #5
          I made a few mistakes with the calculations and I have changed a few of the statements. I am still having one problem though. If I type in a salary figure greater than 33000, it is coming out as a negative value Can someone please tell me were am going wrong.

          Code:
          #include <stdio.h>
          #include <math.h>
          
          int main ()
          
          {
          int salary, NI, pension, part1, part2, part3, part4, part5, part6;
          int part7, part8, part9, part10, part11, part12, part13, part14, part15;
          
          printf("enter your yearly salary");
          scanf("%d",&salary);
          
          	NI= (salary/100)*6;
          	pension=(salary/100)*2;
          
          
          
          	if (salary<=4000)
          		{
          		printf("your yearly salary is %d\n", salary);
          		printf("your yearly tax is %d\n", NI);
          		printf("your yearly pension is %d\n\n",pension);
          		}
          
          
          	if ((salary >= 4001)&&(salary<15000))
          		{
          		part1= salary-4000;
          		part2= (part1/100)*17;
          		part3=NI + part2;
          
          		printf("your salary is %d\n", salary);
          		printf("your yearly tax is %d\n", part3);
          		printf("your yearly pension is %d\n\n", pension);
          		}
          
          
          	if ((salary >= 15001)&&(salary<=30000))
          		{
          		part4= salary-4000;
          		part5= part4-11000;
          		part6= (11000/100)*17;
          		part7= (part5/100)*25;
          		part8= NI+ part6+ part7;
          
          		printf("your salary is %d\n", salary);
          		printf("your yearly tax is %d\n", part8);
          		printf("your yearly pension is %d\n\n", pension);
          		}
          
          
          	if (salary>=30001)
          		{
          		part9= salary-4000;
          		part10= part9-11000;
          		part11= part10-15000;
          
          		part12=(11000/100)*17;
          		part13=(15000/100)*25;
          		part14=(part11/100)*40;
          
          		part15= NI+ part12+ part13+ part14;
          
          
          		printf("your salary is %d\n", salary);
          		printf("your yearly tax is %d\n", part15);
          		printf("your yearly pension is %d\n\n", pension);
          
          		}
          
          return 0;
          
          }
          .

          Comment

          • rajesh6695
            New Member
            • Oct 2006
            • 96

            #6
            I think you are using Turbo C in that compiler The size of int is only 2 bytes so it can store maximum of 32767...So change the Int to unsigned int where you can store maximum of 65535...

            If suppose you are using Turbo C try HELP>>Index>>
            Type int under that search datatype where you can see the maximum and minimum storage capacity...


            int salary, NI, pension, part1, part2, part3, part4, part5, part6;
            int part7, part8, part9, part10, part11, part12, part13, part14, part15;

            as

            unsigned int salary, NI, pension, part1, part2, part3, part4, part5, part6;
            unsigned int part7, part8, part9, part10, part11, part12, part13, part14, part15;

            Comment

            Working...