fork download
  1. //********************************************************
  2. //
  3. // Assignment 10 - Linked Lists, Typedef, and Macros
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 20, 2026
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // This assignment also adds employee name, tax state,
  16. // and calculates state tax, federal tax, and net pay.
  17. // It also calculates totals, averages, minimum, and maximum.
  18. //
  19. // Linked list + typedef + macros version
  20. //
  21. //********************************************************
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <stdlib.h>
  27.  
  28. #define STD_HOURS 40.0
  29. #define OT_RATE 1.5
  30.  
  31. #define MA_TAX_RATE 0.05
  32. #define NH_TAX_RATE 0.0
  33. #define VT_TAX_RATE 0.06
  34. #define CA_TAX_RATE 0.07
  35. #define DEFAULT_STATE_TAX_RATE 0.08
  36.  
  37. #define FED_TAX_RATE 0.25
  38.  
  39. #define NAME_SIZE 20
  40. #define TAX_STATE_SIZE 3
  41. #define FIRST_NAME_SIZE 10
  42. #define LAST_NAME_SIZE 10
  43.  
  44. // Macros
  45. #define CALC_OT_HOURS(theHours) ((theHours > STD_HOURS) ? (theHours - STD_HOURS) : 0)
  46.  
  47. #define CALC_STATE_TAX(thePay,theStateTaxRate) ((thePay) * (theStateTaxRate))
  48.  
  49. // ✅ FIXED FED TAX MACRO
  50. #define CALC_FED_TAX(thePay) ((thePay) * FED_TAX_RATE)
  51.  
  52. #define CALC_NET_PAY(thePay,theStateTax,theFedTax) ((thePay) - ((theStateTax) + (theFedTax)))
  53.  
  54. #define CALC_NORMAL_PAY(theWageRate,theHours,theOvertimeHrs) \
  55. ((theWageRate) * ((theHours) - (theOvertimeHrs)))
  56.  
  57. #define CALC_OT_PAY(theWageRate,theOvertimeHrs) \
  58. ((theOvertimeHrs) * (OT_RATE * (theWageRate)))
  59.  
  60. // ✅ FIXED MIN/MAX MACROS
  61. #define CALC_MIN(theValue, currentMin) (((theValue) < (currentMin)) ? (theValue) : (currentMin))
  62. #define CALC_MAX(theValue, currentMax) (((theValue) > (currentMax)) ? (theValue) : (currentMax))
  63.  
  64. // structures
  65. struct name {
  66. char firstName[FIRST_NAME_SIZE];
  67. char lastName[LAST_NAME_SIZE];
  68. };
  69.  
  70. typedef struct employee {
  71. struct name empName;
  72. char taxState[TAX_STATE_SIZE];
  73. long int clockNumber;
  74. float wageRate;
  75. float hours;
  76. float overtimeHrs;
  77. float grossPay;
  78. float stateTax;
  79. float fedTax;
  80. float netPay;
  81. struct employee *next;
  82. } EMPLOYEE;
  83.  
  84. typedef struct totals {
  85. float total_wageRate;
  86. float total_hours;
  87. float total_overtimeHrs;
  88. float total_grossPay;
  89. float total_stateTax;
  90. float total_fedTax;
  91. float total_netPay;
  92. } TOTALS;
  93.  
  94. // ✅ MIN_MAX typedef added
  95. typedef struct min_max {
  96. float min_wageRate;
  97. float min_hours;
  98. float min_overtimeHrs;
  99. float min_grossPay;
  100. float min_stateTax;
  101. float min_fedTax;
  102. float min_netPay;
  103.  
  104. float max_wageRate;
  105. float max_hours;
  106. float max_overtimeHrs;
  107. float max_grossPay;
  108. float max_stateTax;
  109. float max_fedTax;
  110. float max_netPay;
  111. } MIN_MAX;
  112.  
  113. // prototypes
  114. EMPLOYEE * getEmpData(void);
  115. int isEmployeeSize(EMPLOYEE * head_ptr);
  116. void calcOvertimeHrs(EMPLOYEE * head_ptr);
  117. void calcGrossPay(EMPLOYEE * head_ptr);
  118. void calcStateTax(EMPLOYEE * head_ptr);
  119. void calcFedTax(EMPLOYEE * head_ptr);
  120. void calcNetPay(EMPLOYEE * head_ptr);
  121.  
  122. void calcEmployeeTotals(EMPLOYEE * head_ptr, TOTALS * emp_totals_ptr);
  123.  
  124. void calcEmployeeMinMax(EMPLOYEE * head_ptr, MIN_MAX * emp_minMax_ptr);
  125.  
  126. void printHeader(void);
  127. void printEmp(EMPLOYEE * head_ptr);
  128.  
  129. void printEmpStatistics(TOTALS * emp_totals_ptr, MIN_MAX * emp_minMax_ptr, int size);
  130.  
  131. //**************************************************************
  132. int main()
  133. {
  134. EMPLOYEE *head_ptr;
  135. int theSize;
  136.  
  137. TOTALS employeeTotals = {0};
  138. TOTALS *emp_totals_ptr = &employeeTotals;
  139.  
  140. MIN_MAX employeeMinMax = {0};
  141. MIN_MAX *emp_minMax_ptr = &employeeMinMax;
  142.  
  143. head_ptr = getEmpData();
  144.  
  145. theSize = isEmployeeSize(head_ptr);
  146.  
  147. if (theSize <= 0)
  148. {
  149. printf("\n\n**** There was no employee input to process ***\n");
  150. }
  151. else
  152. {
  153. calcOvertimeHrs(head_ptr);
  154. calcGrossPay(head_ptr);
  155. calcStateTax(head_ptr);
  156. calcFedTax(head_ptr);
  157. calcNetPay(head_ptr);
  158.  
  159. calcEmployeeTotals(head_ptr, emp_totals_ptr);
  160. calcEmployeeMinMax(head_ptr, emp_minMax_ptr);
  161.  
  162. printHeader();
  163. printEmp(head_ptr);
  164. printEmpStatistics(emp_totals_ptr, emp_minMax_ptr, theSize);
  165. }
  166.  
  167. printf("\n\n *** End of Program *** \n");
  168. return 0;
  169. }
  170.  
  171. //**************************************************************
  172. EMPLOYEE * getEmpData(void)
  173. {
  174. EMPLOYEE *head_ptr, *current_ptr;
  175. char answer[10];
  176. int more_data = 1;
  177.  
  178. head_ptr = malloc(sizeof(EMPLOYEE));
  179. current_ptr = head_ptr;
  180.  
  181. while (more_data)
  182. {
  183. printf("\nEnter employee first name: ");
  184. scanf("%s", current_ptr->empName.firstName);
  185.  
  186. printf("\nEnter employee last name: ");
  187. scanf("%s", current_ptr->empName.lastName);
  188.  
  189. printf("\nEnter employee tax state: ");
  190. scanf("%s", current_ptr->taxState);
  191.  
  192. printf("\nEnter clock number: ");
  193. scanf("%li", &current_ptr->clockNumber);
  194.  
  195. printf("\nEnter wage rate: ");
  196. scanf("%f", &current_ptr->wageRate);
  197.  
  198. printf("\nEnter hours: ");
  199. scanf("%f", &current_ptr->hours);
  200.  
  201. printf("\nAnother employee? (y/n): ");
  202. scanf("%s", answer);
  203.  
  204. if (toupper(answer[0]) != 'Y')
  205. {
  206. current_ptr->next = NULL;
  207. more_data = 0;
  208. }
  209. else
  210. {
  211. current_ptr->next = malloc(sizeof(EMPLOYEE));
  212. current_ptr = current_ptr->next;
  213. }
  214. }
  215.  
  216. return head_ptr;
  217. }
  218.  
  219. //**************************************************************
  220. int isEmployeeSize(EMPLOYEE *head_ptr)
  221. {
  222. int count = 0;
  223. EMPLOYEE *cur;
  224.  
  225. for (cur = head_ptr; cur; cur = cur->next)
  226. count++;
  227.  
  228. return count;
  229. }
  230.  
  231. //**************************************************************
  232. void calcOvertimeHrs(EMPLOYEE *head_ptr)
  233. {
  234. EMPLOYEE *cur;
  235. for (cur = head_ptr; cur; cur = cur->next)
  236. cur->overtimeHrs = CALC_OT_HOURS(cur->hours);
  237. }
  238.  
  239. //**************************************************************
  240. void calcGrossPay(EMPLOYEE *head_ptr)
  241. {
  242. EMPLOYEE *cur;
  243. float normal, ot;
  244.  
  245. for (cur = head_ptr; cur; cur = cur->next)
  246. {
  247. normal = CALC_NORMAL_PAY(cur->wageRate, cur->hours, cur->overtimeHrs);
  248. ot = CALC_OT_PAY(cur->wageRate, cur->overtimeHrs);
  249. cur->grossPay = normal + ot;
  250. }
  251. }
  252.  
  253. //**************************************************************
  254. void calcStateTax(EMPLOYEE *head_ptr)
  255. {
  256. EMPLOYEE *cur;
  257.  
  258. for (cur = head_ptr; cur; cur = cur->next)
  259. {
  260. if (strcmp(cur->taxState, "MA") == 0)
  261. cur->stateTax = CALC_STATE_TAX(cur->grossPay, MA_TAX_RATE);
  262. else if (strcmp(cur->taxState, "VT") == 0)
  263. cur->stateTax = CALC_STATE_TAX(cur->grossPay, VT_TAX_RATE);
  264. else if (strcmp(cur->taxState, "NH") == 0)
  265. cur->stateTax = CALC_STATE_TAX(cur->grossPay, NH_TAX_RATE);
  266. else if (strcmp(cur->taxState, "CA") == 0)
  267. cur->stateTax = CALC_STATE_TAX(cur->grossPay, CA_TAX_RATE);
  268. else
  269. cur->stateTax = CALC_STATE_TAX(cur->grossPay, DEFAULT_STATE_TAX_RATE);
  270. }
  271. }
  272.  
  273. //**************************************************************
  274. void calcFedTax(EMPLOYEE *head_ptr)
  275. {
  276. EMPLOYEE *cur;
  277.  
  278. for (cur = head_ptr; cur; cur = cur->next)
  279. cur->fedTax = CALC_FED_TAX(cur->grossPay);
  280. }
  281.  
  282. //**************************************************************
  283. void calcNetPay(EMPLOYEE *head_ptr)
  284. {
  285. EMPLOYEE *cur;
  286.  
  287. for (cur = head_ptr; cur; cur = cur->next)
  288. cur->netPay = CALC_NET_PAY(cur->grossPay, cur->stateTax, cur->fedTax);
  289. }
  290.  
  291. //**************************************************************
  292. void calcEmployeeTotals(EMPLOYEE *head_ptr, TOTALS *t)
  293. {
  294. EMPLOYEE *cur;
  295.  
  296. for (cur = head_ptr; cur; cur = cur->next)
  297. {
  298. t->total_wageRate += cur->wageRate;
  299. t->total_hours += cur->hours;
  300. t->total_overtimeHrs += cur->overtimeHrs;
  301. t->total_grossPay += cur->grossPay;
  302. t->total_stateTax += cur->stateTax;
  303. t->total_fedTax += cur->fedTax;
  304. t->total_netPay += cur->netPay;
  305. }
  306. }
  307.  
  308. //**************************************************************
  309. void calcEmployeeMinMax(EMPLOYEE *head_ptr, MIN_MAX *m)
  310. {
  311. EMPLOYEE *cur = head_ptr;
  312.  
  313. m->min_wageRate = m->max_wageRate = cur->wageRate;
  314. m->min_hours = m->max_hours = cur->hours;
  315. m->min_overtimeHrs = m->max_overtimeHrs = cur->overtimeHrs;
  316. m->min_grossPay = m->max_grossPay = cur->grossPay;
  317. m->min_stateTax = m->max_stateTax = cur->stateTax;
  318. m->min_fedTax = m->max_fedTax = cur->fedTax;
  319. m->min_netPay = m->max_netPay = cur->netPay;
  320.  
  321. cur = cur->next;
  322.  
  323. for (; cur; cur = cur->next)
  324. {
  325. m->min_wageRate = CALC_MIN(cur->wageRate, m->min_wageRate);
  326. m->max_wageRate = CALC_MAX(cur->wageRate, m->max_wageRate);
  327.  
  328. m->min_hours = CALC_MIN(cur->hours, m->min_hours);
  329. m->max_hours = CALC_MAX(cur->hours, m->max_hours);
  330.  
  331. m->min_overtimeHrs = CALC_MIN(cur->overtimeHrs, m->min_overtimeHrs);
  332. m->max_overtimeHrs = CALC_MAX(cur->overtimeHrs, m->max_overtimeHrs);
  333.  
  334. m->min_grossPay = CALC_MIN(cur->grossPay, m->min_grossPay);
  335. m->max_grossPay = CALC_MAX(cur->grossPay, m->max_grossPay);
  336.  
  337. m->min_stateTax = CALC_MIN(cur->stateTax, m->min_stateTax);
  338. m->max_stateTax = CALC_MAX(cur->stateTax, m->max_stateTax);
  339.  
  340. m->min_fedTax = CALC_MIN(cur->fedTax, m->min_fedTax);
  341. m->max_fedTax = CALC_MAX(cur->fedTax, m->max_fedTax);
  342.  
  343. m->min_netPay = CALC_MIN(cur->netPay, m->min_netPay);
  344. m->max_netPay = CALC_MAX(cur->netPay, m->max_netPay);
  345. }
  346. }
  347.  
  348. //**************************************************************
  349. void printHeader(void)
  350. {
  351. printf("\n\n*** Pay Calculator ***\n");
  352. printf("\n---------------------------------------------------------------------------------");
  353. printf("\nName Tax Clock# Wage Hours OT Gross State Fed Net");
  354. printf("\n State Pay Tax Tax Pay");
  355. printf("\n---------------------------------------------------------------------------------");
  356. }
  357.  
  358. //**************************************************************
  359. void printEmp(EMPLOYEE *head_ptr)
  360. {
  361. EMPLOYEE *cur;
  362. char name[30];
  363.  
  364. for (cur = head_ptr; cur; cur = cur->next)
  365. {
  366. strcpy(name, cur->empName.firstName);
  367. strcat(name, " ");
  368. strcat(name, cur->empName.lastName);
  369.  
  370. printf("\n%-20s %-2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  371. name,
  372. cur->taxState,
  373. cur->clockNumber,
  374. cur->wageRate,
  375. cur->hours,
  376. cur->overtimeHrs,
  377. cur->grossPay,
  378. cur->stateTax,
  379. cur->fedTax,
  380. cur->netPay);
  381. }
  382. }
  383.  
  384. //**************************************************************
  385. void printEmpStatistics(TOTALS *t, MIN_MAX *m, int size)
  386. {
  387. printf("\n---------------------------------------------------------------------------------");
  388.  
  389. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  390. t->total_wageRate,
  391. t->total_hours,
  392. t->total_overtimeHrs,
  393. t->total_grossPay,
  394. t->total_stateTax,
  395. t->total_fedTax,
  396. t->total_netPay);
  397.  
  398. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  399. t->total_wageRate/size,
  400. t->total_hours/size,
  401. t->total_overtimeHrs/size,
  402. t->total_grossPay/size,
  403. t->total_stateTax/size,
  404. t->total_fedTax/size,
  405. t->total_netPay/size);
  406.  
  407. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  408. m->min_wageRate,
  409. m->min_hours,
  410. m->min_overtimeHrs,
  411. m->min_grossPay,
  412. m->min_stateTax,
  413. m->min_fedTax,
  414. m->min_netPay);
  415.  
  416. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  417. m->max_wageRate,
  418. m->max_hours,
  419. m->max_overtimeHrs,
  420. m->max_grossPay,
  421. m->max_stateTax,
  422. m->max_fedTax,
  423. m->max_netPay);
  424.  
  425. printf("\n\nThe total employees processed was: %d\n", size);
  426. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Enter employee first name: 
Enter employee last name: 
Enter employee tax state: 
Enter clock number: 
Enter wage rate: 
Enter hours: 
Another employee? (y/n): 

*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock#  Wage   Hours  OT   Gross   State  Fed      Net
                    State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
                         000000   0.00   0.0   0.0     0.00    0.00     0.00      0.00
---------------------------------------------------------------------------------
Totals:                           0.00   0.0   0.0    0.00   0.00    0.00     0.00
Averages:                         0.00   0.0   0.0    0.00   0.00    0.00     0.00
Minimum:                          0.00   0.0   0.0    0.00   0.00    0.00     0.00
Maximum:                          0.00   0.0   0.0    0.00   0.00    0.00     0.00

The total employees processed was: 1


 *** End of Program ***