fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: <Isaac Boahndao>
  6. //
  7. // Class: C Programming, <Spring Semester and 2025>
  8. //
  9. // Date: <03_02_25>
  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. // All functions are called by value
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. // Constants
  22. #define SIZE 5
  23. #define OVERTIME_RATE 1.5
  24. #define STD_WORK_WEEK 40.0
  25.  
  26. // Function prototypes
  27. float getHours(long int clockNumber);
  28. void printHeader(void);
  29. void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay);
  30. float calculateOvertime(float hours);
  31. float calculateGrossPay(float wageRate, float hours, float overtimeHrs);
  32.  
  33. int main() {
  34. // Employee data
  35. long int clockNumber[SIZE] = {98401, 52648, 76534, 34645, 12761};
  36. float grossPay[SIZE];
  37. float hours[SIZE];
  38. float overtimeHrs[SIZE];
  39. float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
  40.  
  41. // Process each employee
  42. for (int i = 0; i < SIZE; i++) {
  43. // Read hours for employee
  44. hours[i] = getHours(clockNumber[i]);
  45.  
  46. // Calculate overtime hours
  47. overtimeHrs[i] = calculateOvertime(hours[i]);
  48.  
  49. // Calculate gross pay
  50. grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
  51. }
  52.  
  53. // Print the header info
  54. printHeader();
  55.  
  56. // Print all employees
  57. for (int i = 0; i < SIZE; i++) {
  58. printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  59. }
  60.  
  61. return 0;
  62. }
  63.  
  64. // Function: getHours
  65. // Purpose: Obtains input from user, the number of hours worked per employee and stores the result.
  66. float getHours(long int clockNumber) {
  67. float hoursWorked;
  68. printf("Enter hours worked for employee ID %ld: ", clockNumber);
  69. scanf("%f", &hoursWorked);
  70. return hoursWorked;
  71. }
  72.  
  73. // Function: printHeader
  74. // Purpose: Prints the header for the employee summary output
  75. void printHeader(void) {
  76. printf("\nEmployee Summary:\n");
  77. printf("---------------------------------------------------------\n");
  78. printf("Employee ID | Wage Rate | Hours Worked | Overtime Hours | Gross Pay\n");
  79. printf("---------------------------------------------------------\n");
  80. }
  81.  
  82. // Function: printEmp
  83. // Purpose: Prints the details for each employee
  84. void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay) {
  85. printf("%10ld | %9.2f | %12.2f | %14.2f | %9.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
  86. }
  87.  
  88. // Function: calculateOvertime
  89. // Purpose: Calculates the overtime hours worked
  90. float calculateOvertime(float hours) {
  91. if (hours > STD_WORK_WEEK) {
  92. return hours - STD_WORK_WEEK;
  93. }
  94. return 0.0;
  95. }
  96.  
  97. // Function: calculateGrossPay
  98. // Purpose: Calculates the gross pay based on wage rate, hours worked, and overtime
  99. float calculateGrossPay(float wageRate, float hours, float overtimeHrs) {
  100. float regularPay = wageRate * (hours - overtimeHrs);
  101. float overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  102. return regularPay + overtimePay;
  103. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter hours worked for employee ID 98401: Enter hours worked for employee ID 52648: Enter hours worked for employee ID 76534: Enter hours worked for employee ID 34645: Enter hours worked for employee ID 12761: 
Employee Summary:
---------------------------------------------------------
Employee ID | Wage Rate | Hours Worked | Overtime Hours | Gross Pay
---------------------------------------------------------
     98401 |     10.60 |         0.00 |           0.00 |      0.00
     52648 |      9.75 |         0.00 |           0.00 |      0.00
     76534 |     10.50 |         0.00 |           0.00 |      0.00
     34645 |     12.25 |         0.00 |           0.00 |      0.00
     12761 |      8.35 |         0.00 |           0.00 |      0.00