fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Employee Pay Calculator with Character Strings
  4. //
  5. // Name: Felix Henriquez
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: November 2, 2025
  10. //
  11. // Description: Extended employee pay calculator using structures,
  12. // character strings, and tax calculations to determine
  13. // state tax, federal tax, and net pay with summary stats.
  14. //
  15. //********************************************************
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #define SIZE 5
  20. #define NAMELEN 10
  21. #define STATE_LEN 3
  22. #define OVERTIME_RATE 1.5
  23. #define STD_HOURS 40.0
  24. #define FED_TAX_RATE 0.25
  25.  
  26. /* Define structures */
  27. struct name {
  28. char firstName[NAMELEN];
  29. char lastName[NAMELEN];
  30. };
  31.  
  32. struct employee {
  33. struct name empName;
  34. char taxState[STATE_LEN];
  35. long int clockNumber;
  36. float wageRate;
  37. float hours;
  38. float overtimeHrs;
  39. float grossPay;
  40. float stateTax;
  41. float fedTax;
  42. float netPay;
  43. };
  44.  
  45. /* Function prototypes */
  46. float computeGross(float hours, float wage);
  47. float computeStateTax(float gross, char state[]);
  48. float findMin(float a, float b);
  49. float findMax(float a, float b);
  50.  
  51. int main(void) {
  52. struct employee emp[SIZE] = {
  53. {{"Connie", "Cobol"}, "MA", 98401, 10.60},
  54. {{"Mary", "Apl"}, "NH", 526488, 9.75},
  55. {{"Frank", "Fortran"}, "VT", 765349, 10.50},
  56. {{"Jeff", "Ada"}, "NY", 34645, 12.25},
  57. {{"Anton", "Pascal"}, "CA", 127615, 8.35}
  58. };
  59.  
  60. float totalWage = 0.0, totalHours = 0.0, totalOT = 0.0;
  61. float totalGross = 0.0, totalState = 0.0, totalFed = 0.0, totalNet = 0.0;
  62. float minWage, minHours, minOT, minGross, minState, minFed, minNet;
  63. float maxWage, maxHours, maxOT, maxGross, maxState, maxFed, maxNet;
  64.  
  65. int i;
  66.  
  67. printf("*** Pay Calculator ***\n\n");
  68. printf("---------------------------------------------------------------------------------\n");
  69. printf("Name Tax Clock# Wage Hours OT Gross State Fed Net\n");
  70. printf(" State Pay Tax Tax Pay\n");
  71. printf("---------------------------------------------------------------------------------\n");
  72.  
  73. /* Input hours for each employee */
  74. for (i = 0; i < SIZE; i++) {
  75. scanf("%f", &emp[i].hours);
  76. }
  77.  
  78. /* Initialize mins and maxes with first employee */
  79. emp[0].overtimeHrs = (emp[0].hours > STD_HOURS) ? emp[0].hours - STD_HOURS : 0.0;
  80. emp[0].grossPay = computeGross(emp[0].hours, emp[0].wageRate);
  81. emp[0].stateTax = computeStateTax(emp[0].grossPay, emp[0].taxState);
  82. emp[0].fedTax = emp[0].grossPay * FED_TAX_RATE;
  83. emp[0].netPay = emp[0].grossPay - (emp[0].stateTax + emp[0].fedTax);
  84.  
  85. minWage = maxWage = emp[0].wageRate;
  86. minHours = maxHours = emp[0].hours;
  87. minOT = maxOT = emp[0].overtimeHrs;
  88. minGross = maxGross = emp[0].grossPay;
  89. minState = maxState = emp[0].stateTax;
  90. minFed = maxFed = emp[0].fedTax;
  91. minNet = maxNet = emp[0].netPay;
  92.  
  93. /* Process each employee */
  94. for (i = 0; i < SIZE; i++) {
  95. emp[i].overtimeHrs = (emp[i].hours > STD_HOURS) ? emp[i].hours - STD_HOURS : 0.0;
  96. emp[i].grossPay = computeGross(emp[i].hours, emp[i].wageRate);
  97. emp[i].stateTax = computeStateTax(emp[i].grossPay, emp[i].taxState);
  98. emp[i].fedTax = emp[i].grossPay * FED_TAX_RATE;
  99. emp[i].netPay = emp[i].grossPay - (emp[i].stateTax + emp[i].fedTax);
  100.  
  101. /* Update totals */
  102. totalWage += emp[i].wageRate;
  103. totalHours += emp[i].hours;
  104. totalOT += emp[i].overtimeHrs;
  105. totalGross += emp[i].grossPay;
  106. totalState += emp[i].stateTax;
  107. totalFed += emp[i].fedTax;
  108. totalNet += emp[i].netPay;
  109.  
  110. /* Update min/max */
  111. minWage = findMin(minWage, emp[i].wageRate);
  112. minHours = findMin(minHours, emp[i].hours);
  113. minOT = findMin(minOT, emp[i].overtimeHrs);
  114. minGross = findMin(minGross, emp[i].grossPay);
  115. minState = findMin(minState, emp[i].stateTax);
  116. minFed = findMin(minFed, emp[i].fedTax);
  117. minNet = findMin(minNet, emp[i].netPay);
  118.  
  119. maxWage = findMax(maxWage, emp[i].wageRate);
  120. maxHours = findMax(maxHours, emp[i].hours);
  121. maxOT = findMax(maxOT, emp[i].overtimeHrs);
  122. maxGross = findMax(maxGross, emp[i].grossPay);
  123. maxState = findMax(maxState, emp[i].stateTax);
  124. maxFed = findMax(maxFed, emp[i].fedTax);
  125. maxNet = findMax(maxNet, emp[i].netPay);
  126.  
  127. /* Print employee row */
  128. printf("%-10s %-10s %-3s %06ld %7.2f %6.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n",
  129. emp[i].empName.firstName,
  130. emp[i].empName.lastName,
  131. emp[i].taxState,
  132. emp[i].clockNumber,
  133. emp[i].wageRate,
  134. emp[i].hours,
  135. emp[i].overtimeHrs,
  136. emp[i].grossPay,
  137. emp[i].stateTax,
  138. emp[i].fedTax,
  139. emp[i].netPay);
  140. }
  141.  
  142. printf("---------------------------------------------------------------------------------\n");
  143. printf("Totals: %5.2f %6.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n",
  144. totalWage, totalHours, totalOT, totalGross, totalState, totalFed, totalNet);
  145. printf("Averages: %5.2f %6.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n",
  146. totalWage / SIZE, totalHours / SIZE, totalOT / SIZE, totalGross / SIZE,
  147. totalState / SIZE, totalFed / SIZE, totalNet / SIZE);
  148. printf("Minimum: %5.2f %6.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n",
  149. minWage, minHours, minOT, minGross, minState, minFed, minNet);
  150. printf("Maximum: %5.2f %6.1f %5.1f %8.2f %7.2f %7.2f %8.2f\n",
  151. maxWage, maxHours, maxOT, maxGross, maxState, maxFed, maxNet);
  152.  
  153. return 0;
  154. }
  155.  
  156. /* Compute gross pay */
  157. float computeGross(float hours, float wage) {
  158. float gross;
  159. if (hours > STD_HOURS)
  160. gross = STD_HOURS * wage + (hours - STD_HOURS) * wage * OVERTIME_RATE;
  161. else
  162. gross = hours * wage;
  163. return gross;
  164. }
  165.  
  166. /* Compute state tax */
  167. float computeStateTax(float gross, char state[]) {
  168. float rate;
  169. if (strcmp(state, "MA") == 0)
  170. rate = 0.05;
  171. else if (strcmp(state, "NH") == 0)
  172. rate = 0.0;
  173. else if (strcmp(state, "VT") == 0)
  174. rate = 0.06;
  175. else if (strcmp(state, "CA") == 0)
  176. rate = 0.07;
  177. else
  178. rate = 0.08;
  179. return gross * rate;
  180. }
  181.  
  182. /* Find minimum */
  183. float findMin(float a, float b) {
  184. return (a < b) ? a : b;
  185. }
  186.  
  187. /* Find maximum */
  188. float findMax(float a, float b) {
  189. return (a > b) ? a : b;
  190. }
  191.  
Success #stdin #stdout 0.01s 5296KB
stdin
51.0
42.5
37.0
45.0
40.0
stdout
*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock#  Wage   Hours  OT   Gross   State  Fed      Net
                    State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
Connie     Cobol      MA  098401   10.60   51.0  11.0   598.90   29.95  149.73   419.23
Mary       Apl        NH  526488    9.75   42.5   2.5   426.56    0.00  106.64   319.92
Frank      Fortran    VT  765349   10.50   37.0   0.0   388.50   23.31   97.12   268.07
Jeff       Ada        NY  034645   12.25   45.0   5.0   581.88   46.55  145.47   389.86
Anton      Pascal     CA  127615    8.35   40.0   0.0   334.00   23.38   83.50   227.12
---------------------------------------------------------------------------------
Totals:                          51.45  215.5  18.5  2329.84  123.18  582.46  1624.19
Averages:                        10.29   43.1   3.7   465.97   24.64  116.49   324.84
Minimum:                          8.35   37.0   0.0   334.00    0.00   83.50   227.12
Maximum:                         12.25   51.0  11.0   598.90   46.55  149.73   419.23