473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main (void)
  5.  
  6. {
  7. int salary, NI, pension, part1, part2, part3, part3, part4, part5, part6;
  8. int part7, part8, part9, part10, part11, part12, part13, part14, part15;
  9.  
  10. printf(''enter your yearly salary'');
  11. scanf(''%d'',&salary);
  12.  
  13. NI= (salary/100)*6;
  14. pension=(salary/)*2;
  15.  
  16.        If (salary<4000);
  17.  {
  18.       then
  19.       printf(''your yearly salary is'', salary);
  20.       printf(''your yearly tax is'', NI);
  21.       printf(''your yearly pension is'',pension);
  22. }
  23.  
  24.      If (4001<salary<15000);
  25. {
  26.      part1= salary-4000;
  27.      part2= (part1/)*17;
  28.      part3=NI + part2;
  29. then
  30.     printf(''your salary is'', salary);
  31.     printf(''your yearly tax is'', part3);
  32.     printf(''your yearly pension is'', pension);
  33. }
  34.  
  35.     If (15001salary30000);
  36. {
  37.    part4= salary-4000;
  38.    part5= part4-11000;
  39.    part6= (part4/100)*17;
  40.    part7= (part5/100)*25;
  41.    part8= NI+ part6+ part7;
  42. then
  43.    printf(''your salary is'', salary);
  44.    printf(''your yearly tax is'', part8);
  45.    printf(your yearly pension is'', pension);
  46. }
  47.  
  48.    else (salary>30001);
  49. {
  50.    part9= salary-4000;
  51.    part10= part9-11000;
  52.    part11= part10- 15000;
  53.  
  54.    part12= (part9/100)*17;
  55.    part13=(part10/100)*25;
  56.    part14=(part11/100)*40;
  57.  
  58.    part15= NI+ part12+ part13+ part14;
  59.  
  60. then
  61.   printf(''your salary is'', salary);
  62.   printf(''your yearly tax  is'', part15);
  63.   printf(''your yearly pension is'', pension);
  64.  
  65. }
  66.  
  67. }
  68.  
Feb 15 '07 #1
5 8544
sicarie
4,677 Expert Mod 4TB
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).
Feb 15 '07 #2
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




Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main ()
  5.  
  6. {
  7. int salary, NI, pension, part1, part2, part3, part4, part5, part6;
  8. int part7, part8, part9, part10, part11, part12, part13, part14, part15;
  9.  
  10. printf("enter your yearly salary");
  11. scanf("%d",&salary);
  12.  
  13. NI= (salary/100)*6;
  14. pension=(salary/100)*2;
  15.  
  16.        if (salary<4000);
  17.  {
  18.  
  19.       printf("your yearly salary is %d", salary);
  20.       printf("your yearly tax is %d", NI);
  21.       printf("your yearly pension is %d",pension);
  22. }
  23.  
  24.      if (4001<salary<15000);
  25. {
  26.      part1= salary-4000;
  27.      part2= (part1/100)*17;
  28.      part3=NI + part2;
  29.  
  30.     printf("your salary is %d", salary);
  31.     printf("your yearly tax is %d", part3);
  32.     printf("your yearly pension is %d", pension);
  33. }
  34.  
  35.     if (15001<salary<30000);
  36. {
  37.    part4= salary-4000;
  38.    part5= part4-11000;
  39.    part6= (part4/100)*17;
  40.    part7= (part5/100)*25;
  41.    part8= NI+ part6+ part7;
  42.  
  43.    printf("your salary is %d", salary);
  44.    printf("your yearly tax is %d", part8);
  45.    printf("your yearly pension is %d", pension);
  46. }
  47.  
  48.    if (salary>30001);
  49. {
  50.    part9= salary-4000;
  51.    part10= part9-11000;
  52.    part11= part10- 15000;
  53.  
  54.    part12= (part9/100)*17;
  55.    part13=(part10/100)*25;
  56.    part14=(part11/100)*40;
  57.  
  58.    part15= NI+ part12+ part13+ part14;
  59.  
  60.  
  61.   printf("your salary is %d", salary);
  62.   printf("your yearly tax  is %d", part15);
  63.   printf("your yearly pension is %d", pension);
  64.  
  65. }
  66.  return 0;
  67.  
  68.  
  69. }
Feb 16 '07 #3
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.....


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main ()
  5.  
  6. {
  7. int salary, NI, pension, part1, part2, part3, part4, part5, part6;
  8. int part7, part8, part9, part10, part11, part12, part13, part14, part15;
  9.  
  10. printf("enter your yearly salary");
  11. scanf("%d",&salary);
  12.  
  13. NI= (salary/100)*6;
  14. pension=(salary/100)*2;
  15.  
  16. if (salary<=4000)
  17. {
  18.     printf("your yearly salary is %d\n", salary);
  19.     printf("your yearly tax is %d\n", NI);
  20.     printf("your yearly pension is %d\n\n",pension);
  21. }
  22.  
  23. if ((salary >= 4001)&&(salary<15000))
  24. {
  25.     part1= salary-4000;
  26.     part2= (part1/100)*17;
  27.     part3=NI + part2;
  28.  
  29.     printf("your salary is %d\n", salary);
  30.     printf("your yearly tax is %d\n", part3);
  31.     printf("your yearly pension is %d\n\n", pension);
  32. }
  33.  
  34. if ((salary >= 15001)&&(salary<=30000))
  35. {
  36.     part4= salary-4000;
  37.     part5= part4-11000;
  38.     part6= (part4/100)*17;
  39.     part7= (part5/100)*25;
  40.     part8= NI+ part6+ part7;
  41.  
  42.     printf("your salary is %d\n", salary);
  43.     printf("your yearly tax is %d\n", part8);
  44.     printf("your yearly pension is %d\n\n", pension);
  45. }
  46.  
  47. if (salary>=30001)
  48. {
  49.     part9= salary-4000;
  50.     part10= part9-11000;
  51.     part11= part10- 15000;
  52.  
  53.     part12= (part9/100)*17;
  54.     part13=(part10/100)*25;
  55.     part14=(part11/100)*40;
  56.  
  57.     part15= NI+ part12+ part13+ part14;
  58.  
  59.  
  60.     printf("your salary is %d\n", salary);
  61.     printf("your yearly tax is %d\n", part15);
  62.     printf("your yearly pension is %d\n\n", pension);
  63.  
  64. }
  65. return 0;
  66.  
  67.  
  68. }
Feb 16 '07 #4
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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main ()
  5.  
  6. {
  7. int salary, NI, pension, part1, part2, part3, part4, part5, part6;
  8. int part7, part8, part9, part10, part11, part12, part13, part14, part15;
  9.  
  10. printf("enter your yearly salary");
  11. scanf("%d",&salary);
  12.  
  13.     NI= (salary/100)*6;
  14.     pension=(salary/100)*2;
  15.  
  16.  
  17.  
  18.     if (salary<=4000)
  19.         {
  20.         printf("your yearly salary is %d\n", salary);
  21.         printf("your yearly tax is %d\n", NI);
  22.         printf("your yearly pension is %d\n\n",pension);
  23.         }
  24.  
  25.  
  26.     if ((salary >= 4001)&&(salary<15000))
  27.         {
  28.         part1= salary-4000;
  29.         part2= (part1/100)*17;
  30.         part3=NI + part2;
  31.  
  32.         printf("your salary is %d\n", salary);
  33.         printf("your yearly tax is %d\n", part3);
  34.         printf("your yearly pension is %d\n\n", pension);
  35.         }
  36.  
  37.  
  38.     if ((salary >= 15001)&&(salary<=30000))
  39.         {
  40.         part4= salary-4000;
  41.         part5= part4-11000;
  42.         part6= (11000/100)*17;
  43.         part7= (part5/100)*25;
  44.         part8= NI+ part6+ part7;
  45.  
  46.         printf("your salary is %d\n", salary);
  47.         printf("your yearly tax is %d\n", part8);
  48.         printf("your yearly pension is %d\n\n", pension);
  49.         }
  50.  
  51.  
  52.     if (salary>=30001)
  53.         {
  54.         part9= salary-4000;
  55.         part10= part9-11000;
  56.         part11= part10-15000;
  57.  
  58.         part12=(11000/100)*17;
  59.         part13=(15000/100)*25;
  60.         part14=(part11/100)*40;
  61.  
  62.         part15= NI+ part12+ part13+ part14;
  63.  
  64.  
  65.         printf("your salary is %d\n", salary);
  66.         printf("your yearly tax is %d\n", part15);
  67.         printf("your yearly pension is %d\n\n", pension);
  68.  
  69.         }
  70.  
  71. return 0;
  72.  
  73. }
.
Feb 16 '07 #5
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;
Feb 16 '07 #6

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

Similar topics

2
by: Deano | last post by:
OK, I'm working on a solution to the following problem but there are other ways to skin a cat as they say... Here's the table (simplified); ID EmployeeName SalaryAcc 1 Brown ...
5
by: Stu | last post by:
What are .NET programmers making now a days? No one has to answer or give their exact salary, but I think it might be useful for those of us who think they might be underpaid :) I know it varies a...
1
by: sallyk57 | last post by:
Help with following Programs: Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will...
1
by: punkybrewster | last post by:
Basically my task is to write a program that computes and displays the weekly salaries of a company's salespeople based upon information entered by the user and that also displays the total for the...
133
by: muhes | last post by:
Hello, I am working on a project for my department to design a form to calculate budgets. I really don't know much about access or programming in general. At this point, I am trying to design a...
8
by: hmmtn | last post by:
I would appreciate any help on this one. Assignment is as follows: Develop a program that will determine the gross pay for each of several employees. The company pays "straight time" for the first...
4
by: sonia.sardana | last post by:
I know how how to retrive the largest & second largest salary. tell me how to retrive the 3,4,5,...............Largest salary. Create table empl(empid int, empname varchar,salary int) insert...
1
by: shivanee | last post by:
I am using 2 froms i.e salaryinfo is the main form, and salaryincrement is the subform. By selecting the empno i hv to enter his joining salary i.e.totalctc . If there is any increment then i hv to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.