fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Employee Pay Calculator with Structures
  4. //
  5. // Name: Felix Henriquez
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 19, 2025
  10. //
  11. // Description: Employee pay calculator using structures
  12. // to determine overtime and gross pay.
  13. //
  14. //********************************************************
  15.  
  16. #include <stdio.h>
  17.  
  18. // Constants for business rules
  19. #define MAX_EMPLOYEES 5
  20. #define OVERTIME_RATE 1.5f
  21. #define STANDARD_WORK_WEEK 40.0f
  22. #define COMPANY_NAME "Henriquez Solutions"
  23.  
  24. // Structure definition
  25. struct employee
  26. {
  27. long int clockNumber;
  28. float wageRate;
  29. float hours;
  30. float overtimeHrs;
  31. float grossPay;
  32. };
  33.  
  34. // Function prototypes
  35. void displayWelcomeMessage(void);
  36. void getEmployeeHours(struct employee employees[]);
  37. void computeOvertime(struct employee employees[]);
  38. void computeGrossPay(struct employee employees[]);
  39. void displayPayReport(struct employee employees[]);
  40. void displayPaySummary(struct employee employees[]);
  41. void calculateTotals(struct employee employees[], float totals[], float averages[]);
  42.  
  43. int main()
  44. {
  45. // Initialize array of structures
  46. struct employee employees[MAX_EMPLOYEES] = {
  47. {98401, 10.60, 0, 0, 0},
  48. {526488, 9.75, 0, 0, 0},
  49. {765349, 10.50, 0, 0, 0},
  50. {34645, 12.25, 0, 0, 0},
  51. {127615, 8.35, 0, 0, 0}
  52. };
  53.  
  54. // Display welcome message
  55. displayWelcomeMessage();
  56.  
  57. // Get employee work hours
  58. getEmployeeHours(employees);
  59.  
  60. // Calculate payroll components
  61. computeOvertime(employees);
  62. computeGrossPay(employees);
  63.  
  64. // Display results
  65. displayPayReport(employees);
  66. displayPaySummary(employees);
  67.  
  68. printf("\n*** Payroll processing complete! ***\n");
  69. return 0;
  70. }
  71.  
  72. //**************************************************************
  73. // Function: displayWelcomeMessage
  74. //
  75. // Purpose: Displays a welcome message and company header
  76. //
  77. // Parameters: none
  78. //
  79. // Returns: void
  80. //
  81. //**************************************************************
  82. void displayWelcomeMessage(void)
  83. {
  84. printf("\n==================================================");
  85. printf("\n %s", COMPANY_NAME);
  86. printf("\n PAYROLL SYSTEM v3.0 (Structures)");
  87. printf("\n==================================================\n");
  88. printf("\nWelcome to the Employee Pay Calculator!\n");
  89. printf("Please enter the hours worked for each employee.\n");
  90. }
  91.  
  92. //**************************************************************
  93. // Function: getEmployeeHours
  94. //
  95. // Purpose: Collects hours worked for each employee with validation
  96. //
  97. // Parameters: employees[] - array of employee structures
  98. //
  99. // Returns: void
  100. //
  101. //**************************************************************
  102. void getEmployeeHours(struct employee employees[])
  103. {
  104. int i; // loop counter
  105.  
  106. printf("\n--------------------------------------------------\n");
  107. printf("ENTER EMPLOYEE HOURS:\n");
  108. printf("--------------------------------------------------\n");
  109.  
  110. for (i = 0; i < MAX_EMPLOYEES; ++i)
  111. {
  112. printf("Hours for Employee #%d (Clock# %06ld): ", i + 1, employees[i].clockNumber);
  113. scanf("%f", &employees[i].hours);
  114.  
  115. // Basic validation
  116. if (employees[i].hours < 0)
  117. {
  118. printf(" Note: Negative hours entered. Setting to 0.\n");
  119. employees[i].hours = 0.0;
  120. }
  121. else if (employees[i].hours > 80)
  122. {
  123. printf(" Note: Hours exceed 80. Please verify.\n");
  124. }
  125. }
  126. }
  127.  
  128. //**************************************************************
  129. // Function: computeOvertime
  130. //
  131. // Purpose: Calculates overtime hours for each employee
  132. //
  133. // Parameters: employees[] - array of employee structures
  134. //
  135. // Returns: void
  136. //
  137. //**************************************************************
  138. void computeOvertime(struct employee employees[])
  139. {
  140. int i; // loop counter
  141.  
  142. for (i = 0; i < MAX_EMPLOYEES; ++i)
  143. {
  144. if (employees[i].hours > STANDARD_WORK_WEEK)
  145. {
  146. employees[i].overtimeHrs = employees[i].hours - STANDARD_WORK_WEEK;
  147. }
  148. else
  149. {
  150. employees[i].overtimeHrs = 0.0;
  151. }
  152. }
  153. }
  154.  
  155. //**************************************************************
  156. // Function: computeGrossPay
  157. //
  158. // Purpose: Calculates total pay including overtime
  159. //
  160. // Parameters: employees[] - array of employee structures
  161. //
  162. // Returns: void
  163. //
  164. //**************************************************************
  165. void computeGrossPay(struct employee employees[])
  166. {
  167. int i; // loop counter
  168. float regularHours; // non-overtime hours
  169. float basePay; // pay for regular hours
  170. float premiumPay; // pay for overtime hours
  171.  
  172. for (i = 0; i < MAX_EMPLOYEES; ++i)
  173. {
  174. // Determine regular hours (capped at 40)
  175. regularHours = (employees[i].hours > STANDARD_WORK_WEEK) ? STANDARD_WORK_WEEK : employees[i].hours;
  176.  
  177. // Calculate pay components
  178. basePay = regularHours * employees[i].wageRate;
  179. premiumPay = employees[i].overtimeHrs * employees[i].wageRate * OVERTIME_RATE;
  180.  
  181. // Total compensation
  182. employees[i].grossPay = basePay + premiumPay;
  183. }
  184. }
  185.  
  186. //**************************************************************
  187. // Function: displayPayReport
  188. //
  189. // Purpose: Displays detailed pay report in formatted table
  190. //
  191. // Parameters: employees[] - array of employee structures
  192. //
  193. // Returns: void
  194. //
  195. //**************************************************************
  196. void displayPayReport(struct employee employees[])
  197. {
  198. int i; // loop counter
  199. float totals[5] = {0}; // wage, hours, OT, gross
  200. float averages[5] = {0};
  201.  
  202. // Calculate totals and averages
  203. calculateTotals(employees, totals, averages);
  204.  
  205. printf("\n--------------------------------------------------------------------------");
  206. printf("\n Clock# Wage Hours OT Gross");
  207. printf("\n--------------------------------------------------------------------------");
  208.  
  209. for (i = 0; i < MAX_EMPLOYEES; ++i)
  210. {
  211. printf("\n %06ld %5.2f %5.1f %4.1f %8.2f",
  212. employees[i].clockNumber,
  213. employees[i].wageRate,
  214. employees[i].hours,
  215. employees[i].overtimeHrs,
  216. employees[i].grossPay);
  217. }
  218.  
  219. // Display separator line
  220. printf("\n--------------------------------------------------------------------------");
  221.  
  222. // Display totals
  223. printf("\n Total %5.2f %5.1f %4.1f %8.2f",
  224. totals[0], totals[1], totals[2], totals[3]);
  225.  
  226. // Display averages
  227. printf("\n Average %5.2f %4.1f %3.1f %8.2f",
  228. averages[0], averages[1], averages[2], averages[3]);
  229.  
  230. printf("\n--------------------------------------------------------------------------");
  231. }
  232.  
  233. //**************************************************************
  234. // Function: calculateTotals
  235. //
  236. // Purpose: Calculates totals and averages for the report
  237. //
  238. // Parameters: employees[] - array of employee structures
  239. // totals[] - array to store totals
  240. // averages[] - array to store averages
  241. //
  242. // Returns: void
  243. //
  244. //**************************************************************
  245. void calculateTotals(struct employee employees[], float totals[], float averages[])
  246. {
  247. int i; // loop counter
  248.  
  249. for (i = 0; i < MAX_EMPLOYEES; ++i)
  250. {
  251. totals[0] += employees[i].wageRate; // Sum of wages
  252. totals[1] += employees[i].hours; // Sum of hours
  253. totals[2] += employees[i].overtimeHrs; // Sum of overtime
  254. totals[3] += employees[i].grossPay; // Sum of gross pay
  255. }
  256.  
  257. // Calculate averages
  258. for (i = 0; i < 4; ++i)
  259. {
  260. averages[i] = totals[i] / MAX_EMPLOYEES;
  261. }
  262. }
  263.  
  264. //**************************************************************
  265. // Function: displayPaySummary
  266. //
  267. // Purpose: Displays payroll summary statistics
  268. //
  269. // Parameters: employees[] - array of employee structures
  270. //
  271. // Returns: void
  272. //
  273. //**************************************************************
  274. void displayPaySummary(struct employee employees[])
  275. {
  276. float payrollTotal = 0.0;
  277. float totalHours = 0.0;
  278. float totalOvertime = 0.0;
  279. int i;
  280.  
  281. for (i = 0; i < MAX_EMPLOYEES; ++i)
  282. {
  283. payrollTotal += employees[i].grossPay;
  284. totalHours += employees[i].hours;
  285. totalOvertime += employees[i].overtimeHrs;
  286. }
  287.  
  288. printf("\n\nPAYROLL SUMMARY:");
  289. printf("\n------------------------------------------");
  290. printf("\nTotal Gross Pay: $%9.2f", payrollTotal);
  291. printf("\nAverage Gross Pay: $%9.2f", payrollTotal / MAX_EMPLOYEES);
  292. printf("\nTotal Hours: %9.1f", totalHours);
  293. printf("\nOvertime Hours: %9.1f", totalOvertime);
  294. printf("\nEmployees Processed:%9d", MAX_EMPLOYEES);
  295. printf("\n------------------------------------------\n");
  296. }
Success #stdin #stdout 0s 5320KB
stdin
45.7
27.5
15.0
58.0
0.0
stdout
==================================================
              Henriquez Solutions
        PAYROLL SYSTEM v3.0 (Structures)
==================================================

Welcome to the Employee Pay Calculator!
Please enter the hours worked for each employee.

--------------------------------------------------
ENTER EMPLOYEE HOURS:
--------------------------------------------------
Hours for Employee #1 (Clock# 098401): Hours for Employee #2 (Clock# 526488): Hours for Employee #3 (Clock# 765349): Hours for Employee #4 (Clock# 034645): Hours for Employee #5 (Clock# 127615): 
--------------------------------------------------------------------------
    Clock#   Wage   Hours     OT      Gross
--------------------------------------------------------------------------
   098401   10.60    45.7     5.7      514.63
   526488    9.75    27.5     0.0      268.12
   765349   10.50    15.0     0.0      157.50
   034645   12.25    58.0    18.0      820.75
   127615    8.35     0.0     0.0        0.00
--------------------------------------------------------------------------
   Total    51.45  146.2   23.7    1761.01
   Average  10.29   29.2    4.7     352.20
--------------------------------------------------------------------------

PAYROLL SUMMARY:
------------------------------------------
Total Gross Pay:    $  1761.01
Average Gross Pay:  $   352.20
Total Hours:            146.2
Overtime Hours:          23.7
Employees Processed:        5
------------------------------------------

*** Payroll processing complete! ***