fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Employee Pay Calculator
  4. //
  5. // Name: Felix Henriquez
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 12, 2025
  10. //
  11. // Description: Advanced employee pay calculator that determines
  12. // overtime and gross pay with enhanced features and formatting.
  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. // Function prototypes
  25. void displayWelcomeMessage(void);
  26. void getEmployeeHours(float workHours[]);
  27. void computeOvertime(float workHours[], float overtimeHours[]);
  28. void computeGrossPay(float payRate[], float workHours[], float overtimeHours[], float totalPay[]);
  29. void displayPayReport(long int employeeID[], float payRate[], float workHours[],
  30. float overtimeHours[], float totalPay[]);
  31. void displayPaySummary(float totalPay[]);
  32.  
  33. int main()
  34. {
  35. // Employee database
  36. long int employeeID[MAX_EMPLOYEES] = {98401, 526488, 765349, 34645, 127615};
  37. float payRate[MAX_EMPLOYEES] = {10.60, 9.75, 10.50, 12.25, 8.35};
  38. float workHours[MAX_EMPLOYEES];
  39. float overtimeHours[MAX_EMPLOYEES];
  40. float totalPay[MAX_EMPLOYEES];
  41.  
  42. // Display welcome message
  43. displayWelcomeMessage();
  44.  
  45. // Get employee work hours
  46. getEmployeeHours(workHours);
  47.  
  48. // Calculate payroll components
  49. computeOvertime(workHours, overtimeHours);
  50. computeGrossPay(payRate, workHours, overtimeHours, totalPay);
  51.  
  52. // Display results
  53. displayPayReport(employeeID, payRate, workHours, overtimeHours, totalPay);
  54. displayPaySummary(totalPay);
  55.  
  56. printf("\n*** Payroll processing complete! ***\n");
  57. return 0;
  58. }
  59.  
  60. //**************************************************************
  61. // Function: displayWelcomeMessage
  62. //
  63. // Purpose: Displays a welcome message and company header
  64. //
  65. // Parameters: none
  66. //
  67. // Returns: void
  68. //
  69. //**************************************************************
  70. void displayWelcomeMessage(void)
  71. {
  72. printf("\n==================================================");
  73. printf("\n %s", COMPANY_NAME);
  74. printf("\n PAYROLL SYSTEM v2.0");
  75. printf("\n==================================================\n");
  76. printf("\nWelcome to the Employee Pay Calculator!\n");
  77. printf("Please enter the hours worked for each employee.\n");
  78. }
  79.  
  80. //**************************************************************
  81. // Function: getEmployeeHours
  82. //
  83. // Purpose: Collects hours worked for each employee with validation
  84. //
  85. // Parameters: workHours[] - array to store hours worked
  86. //
  87. // Returns: void
  88. //
  89. //**************************************************************
  90. void getEmployeeHours(float workHours[])
  91. {
  92. int i; // loop counter
  93.  
  94. printf("\n--------------------------------------------------\n");
  95. printf("ENTER EMPLOYEE HOURS:\n");
  96. printf("--------------------------------------------------\n");
  97.  
  98. for (i = 0; i < MAX_EMPLOYEES; ++i)
  99. {
  100. printf("Hours for Employee #%d: ", i + 1);
  101. scanf("%f", &workHours[i]);
  102.  
  103. // Basic validation
  104. if (workHours[i] < 0)
  105. {
  106. printf(" Note: Negative hours entered. Setting to 0.\n");
  107. workHours[i] = 0.0;
  108. }
  109. else if (workHours[i] > 80)
  110. {
  111. printf(" Note: Hours exceed 80. Please verify.\n");
  112. }
  113. }
  114. }
  115.  
  116. //**************************************************************
  117. // Function: computeOvertime
  118. //
  119. // Purpose: Calculates overtime hours for each employee
  120. //
  121. // Parameters: workHours[] - array of hours worked
  122. // overtimeHours[] - array to store overtime hours
  123. //
  124. // Returns: void
  125. //
  126. //**************************************************************
  127. void computeOvertime(float workHours[], float overtimeHours[])
  128. {
  129. int i; // loop counter
  130.  
  131. for (i = 0; i < MAX_EMPLOYEES; ++i)
  132. {
  133. if (workHours[i] > STANDARD_WORK_WEEK)
  134. {
  135. overtimeHours[i] = workHours[i] - STANDARD_WORK_WEEK;
  136. }
  137. else
  138. {
  139. overtimeHours[i] = 0.0;
  140. }
  141. }
  142. }
  143.  
  144. //**************************************************************
  145. // Function: computeGrossPay
  146. //
  147. // Purpose: Calculates total pay including overtime
  148. //
  149. // Parameters: payRate[] - array of hourly pay rates
  150. // workHours[] - array of hours worked
  151. // overtimeHours[] - array of overtime hours
  152. // totalPay[] - array to store gross pay
  153. //
  154. // Returns: void
  155. //
  156. //**************************************************************
  157. void computeGrossPay(float payRate[], float workHours[], float overtimeHours[], float totalPay[])
  158. {
  159. int i; // loop counter
  160. float regularHours; // non-overtime hours
  161. float basePay; // pay for regular hours
  162. float premiumPay; // pay for overtime hours
  163.  
  164. for (i = 0; i < MAX_EMPLOYEES; ++i)
  165. {
  166. // Determine regular hours (capped at 40)
  167. regularHours = (workHours[i] > STANDARD_WORK_WEEK) ? STANDARD_WORK_WEEK : workHours[i];
  168.  
  169. // Calculate pay components
  170. basePay = regularHours * payRate[i];
  171. premiumPay = overtimeHours[i] * payRate[i] * OVERTIME_RATE;
  172.  
  173. // Total compensation
  174. totalPay[i] = basePay + premiumPay;
  175. }
  176. }
  177.  
  178. //**************************************************************
  179. // Function: displayPayReport
  180. //
  181. // Purpose: Displays detailed pay report in formatted table
  182. //
  183. // Parameters: employeeID[] - array of employee IDs
  184. // payRate[] - array of pay rates
  185. // workHours[] - array of hours worked
  186. // overtimeHours[] - array of overtime hours
  187. // totalPay[] - array of gross pay amounts
  188. //
  189. // Returns: void
  190. //
  191. //**************************************************************
  192. void displayPayReport(long int employeeID[], float payRate[], float workHours[],
  193. float overtimeHours[], float totalPay[])
  194. {
  195. int i; // loop counter
  196.  
  197. printf("\n================================================================");
  198. printf("\n PAYROLL REPORT");
  199. printf("\n================================================================");
  200. printf("\n Employee Pay Rate Hours Overtime Gross Pay");
  201. printf("\n------------------------------------------------");
  202.  
  203. for (i = 0; i < MAX_EMPLOYEES; ++i)
  204. {
  205. printf("\n %06li $%5.2f %5.1f %4.1f $%8.2f",
  206. employeeID[i], payRate[i], workHours[i], overtimeHours[i], totalPay[i]);
  207. }
  208.  
  209. printf("\n================================================================");
  210. }
  211.  
  212. //**************************************************************
  213. // Function: displayPaySummary
  214. //
  215. // Purpose: Displays payroll summary statistics
  216. //
  217. // Parameters: totalPay[] - array of gross pay amounts
  218. //
  219. // Returns: void
  220. //
  221. //**************************************************************
  222. void displayPaySummary(float totalPay[])
  223. {
  224. int i; // loop counter
  225. float payrollTotal; // sum of all gross pay
  226. float averagePay; // average gross pay
  227.  
  228. payrollTotal = 0.0;
  229.  
  230. for (i = 0; i < MAX_EMPLOYEES; ++i)
  231. {
  232. payrollTotal += totalPay[i];
  233. }
  234.  
  235. averagePay = payrollTotal / MAX_EMPLOYEES;
  236.  
  237. printf("\n\nPAYROLL SUMMARY:");
  238. printf("\n------------------------------------------");
  239. printf("\nTotal Payroll: $%9.2f", payrollTotal);
  240. printf("\nAverage Pay: $%9.2f", averagePay);
  241. printf("\nEmployees: %d", MAX_EMPLOYEES);
  242. printf("\n------------------------------------------\n");
  243. }
  244.  
Success #stdin #stdout 0s 5324KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
==================================================
              Henriquez Solutions
              PAYROLL SYSTEM v2.0
==================================================

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

--------------------------------------------------
ENTER EMPLOYEE HOURS:
--------------------------------------------------
Hours for Employee #1: Hours for Employee #2: Hours for Employee #3: Hours for Employee #4: Hours for Employee #5: 
================================================================
                     PAYROLL REPORT
================================================================
   Employee    Pay Rate    Hours     Overtime      Gross Pay
------------------------------------------------
   098401      $10.60      51.0      11.0        $  598.90
   526488      $ 9.75      42.5       2.5        $  426.56
   765349      $10.50      37.0       0.0        $  388.50
   034645      $12.25      45.0       5.0        $  581.88
   127615      $ 8.35       0.0       0.0        $    0.00
================================================================

PAYROLL SUMMARY:
------------------------------------------
Total Payroll:    $  1995.84
Average Pay:      $   399.17
Employees:        5
------------------------------------------

*** Payroll processing complete! ***