Advertisement
Guest User

Untitled

a guest
Aug 15th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define BASIC_PAY_RATE_ONE 8.75
  5. #define BASIC_PAY_RATE_TWO 9.33
  6. #define BASIC_PAY_RATE_THREE 10.00
  7. #define BASIC_PAY_RATE_FOUR 11.20
  8.  
  9. #define EXCESS 40.0
  10. #define OVERTIME 1.5
  11.  
  12. #define FIRST_BORDER 300.00
  13. #define NEXT_BORDER 150.00
  14. #define SECOND_BORDER (FIRST_BORDER + NEXT_BORDER)
  15.  
  16. #define TAX_RATE_ONE 0.15
  17. #define TAX_RATE_TWO 0.20
  18. #define DIFFERENCE_BETWEEN_TAX_RATE_TWO_AND_TAX_RATE_ONE (TAX_RATE_TWO - TAX_RATE_ONE)
  19. #define TAX_RATE_THREE 0.25
  20. #define DIFFERENCE_BETWEEN_TAX_RATE_THREE_AND_TAX_RATE_TWO (TAX_RATE_THREE - TAX_RATE_TWO)
  21.  
  22. int get_num_decision(void);
  23. double get_basic_pay_rate(int num_decision);
  24. double get_additional_pay_rate(double basic_pay_rate);
  25. double get_non_negative_not_too_big(void);
  26. double gross_pay_calc(double hours, double basic_pay_rate, double additional_pay_rate);
  27. double the_taxes_calc(double gross_pay);
  28. void response_output(double gross_pay, double the_taxes);
  29.  
  30. int main(void) {
  31. int num_decision = 0;
  32. double basic_pay_rate = 0, additional_pay_rate = 0;
  33. double hours = 0, gross_pay = 0, the_taxes = 0;
  34. while ((num_decision = get_num_decision()) != 5) {
  35. basic_pay_rate = get_basic_pay_rate(num_decision);
  36. additional_pay_rate = get_additional_pay_rate(basic_pay_rate);
  37. hours = get_non_negative_not_too_big();
  38. gross_pay = gross_pay_calc(hours, basic_pay_rate, additional_pay_rate);
  39. the_taxes = the_taxes_calc(gross_pay);
  40. response_output(gross_pay, the_taxes);
  41. }
  42. return 0;
  43. }
  44.  
  45. int get_num_decision(void) {
  46. printf("Enter the number corresponding to the desired pay rate or action:\n");
  47. printf("1) $%.2f/hr\n", BASIC_PAY_RATE_ONE);
  48. printf("2) $%.2f/hr\n", BASIC_PAY_RATE_TWO);
  49. printf("3) $%.2f/hr\n", BASIC_PAY_RATE_THREE);
  50. printf("4) $%.2f/hr\n", BASIC_PAY_RATE_FOUR);
  51. printf("5) quit\n\n");
  52. int num = 0;
  53. int num_decision = 0;
  54. while (((num = scanf("%d", &num_decision)) != 1) || (num_decision > 5) || (num_decision < 1)) {
  55. if ((num == EOF) || (num == 0))
  56. exit(EXIT_SUCCESS);
  57. printf("You were mistaken\n"
  58. "Enter the value greater than or equal to 1\n"
  59. "And less than or equal to 5: ");
  60. }
  61. while((num = getchar()) != '\n')
  62. if (num == EOF)
  63. exit(EXIT_SUCCESS);
  64. return num_decision;
  65. }
  66.  
  67. double get_basic_pay_rate(int num_decision) {
  68. switch (num_decision) {
  69. case 1 : return BASIC_PAY_RATE_ONE;
  70. case 2 : return BASIC_PAY_RATE_TWO;
  71. case 3 : return BASIC_PAY_RATE_THREE;
  72. case 4 : return BASIC_PAY_RATE_FOUR;
  73. default : exit(EXIT_SUCCESS);
  74. }
  75. }
  76.  
  77. double get_additional_pay_rate(double basic_pay_rate) {
  78. return basic_pay_rate * OVERTIME - basic_pay_rate;
  79. }
  80.  
  81. double get_non_negative_not_too_big(void) {
  82. int num = 0;
  83. double hours = 0;
  84. printf("\nEnter the hours worked in a week: ");
  85. while (((num = scanf("%lf", &hours)) != 1) || (hours < 0) || (hours > 168)) {
  86. if ((num == EOF) || (num == 0))
  87. exit(EXIT_SUCCESS);
  88. printf("You were mistaken\n"
  89. "Enter the value greater than or equal to 0\n"
  90. "And less than or equal to 168: ");
  91. }
  92. while ((num = getchar()) != '\n')
  93. if (num == EOF)
  94. exit(EXIT_SUCCESS);
  95. return hours;
  96. }
  97.  
  98. double gross_pay_calc(double hours, double basic_pay_rate, double additional_pay_rate) {
  99. double gross_pay = hours * basic_pay_rate;
  100. if (hours > EXCESS)
  101. gross_pay += (hours - EXCESS) * additional_pay_rate;
  102. return gross_pay;
  103. }
  104.  
  105. double the_taxes_calc(double gross_pay) {
  106. double the_taxes = gross_pay * TAX_RATE_ONE;
  107. if (gross_pay > FIRST_BORDER)
  108. the_taxes += (gross_pay - FIRST_BORDER) * DIFFERENCE_BETWEEN_TAX_RATE_TWO_AND_TAX_RATE_ONE;
  109. if (gross_pay > SECOND_BORDER)
  110. the_taxes += (gross_pay - SECOND_BORDER) * DIFFERENCE_BETWEEN_TAX_RATE_THREE_AND_TAX_RATE_TWO;
  111. return the_taxes;
  112. }
  113.  
  114. void response_output(double gross_pay, double the_taxes) {
  115. printf("\nGross pay: %.2f\n", gross_pay);
  116. printf("The taxes: %.2f\n", the_taxes);
  117. printf("Net pay: %.2f\n\n", gross_pay - the_taxes);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement