fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Rose Samedi
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 10/19/2025
  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. //********************************************************
  16. #include <stdio.h>
  17.  
  18. // constants to use
  19. #define SIZE 5 // number of employees to process
  20. #define STD_HOURS 40.0 // normal work week hours before overtime
  21. #define OT_RATE 1.5 // time and half overtime setting
  22.  
  23. // Function prototype for printing employee details
  24. void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay);
  25.  
  26. int main() {
  27. // Declare variables needed for the program
  28. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  29. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  30. float hours[SIZE]; // hours worked in a given week
  31. int i; // loop and array index
  32. float normalPay[SIZE]; // normal weekly pay without any overtime
  33. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  34. float overtimePay[SIZE]; // overtime pay for a given week
  35. float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
  36.  
  37. printf("\n*** Pay Calculator ***\n\n");
  38.  
  39. // Loop to get hours worked and calculate pay for each employee
  40. for (i = 0; i < SIZE; i++) {
  41. printf("Enter the hours worked for employee %ld: ", clockNumber[i]);
  42. scanf("%f", &hours[i]);
  43.  
  44. // Calculate overtime and gross pay for the employee
  45. if (hours[i] > STD_HOURS) {
  46. overtimeHrs[i] = hours[i] - STD_HOURS;
  47. normalPay[i] = STD_HOURS * wageRate[i];
  48. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  49. grossPay[i] = normalPay[i] + overtimePay[i];
  50. } else { // No overtime
  51. overtimeHrs[i] = 0.0;
  52. overtimePay[i] = 0.0;
  53. normalPay[i] = hours[i] * wageRate[i];
  54. grossPay[i] = normalPay[i];
  55. }
  56. }
  57.  
  58. // Print a nice table header
  59. printf("\n\n---------------------------------------------------------------\n");
  60. printf("Clock # | Wage | Hours | OT Hrs | OT Pay | Gross Pay\n");
  61. printf("---------------------------------------------------------------\n");
  62.  
  63. // Loop to print employee data
  64. for (i = 0; i < SIZE; i++) {
  65. // Print all the employees using a dedicated function
  66. printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  67. }
  68.  
  69. return 0;
  70. }
  71.  
  72. // Function definition for printEmp
  73. void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay) {
  74. printf("%07ld | $%5.2f | %5.1f | %6.1f | $%6.2f | $%8.2f\n",
  75. clockNumber, wageRate, hours, overtimeHrs, overtimeHrs * wageRate * OT_RATE, grossPay);
  76. }
Success #stdin #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter the hours worked for employee 98401: Enter the hours worked for employee 526488: Enter the hours worked for employee 765349: Enter the hours worked for employee 34645: Enter the hours worked for employee 127615: 

---------------------------------------------------------------
Clock #   | Wage  | Hours | OT Hrs | OT Pay | Gross Pay
---------------------------------------------------------------
0098401 | $10.60 |  51.0 |   11.0 | $174.90 | $  598.90
0526488 | $ 9.75 |  42.5 |    2.5 | $ 36.56 | $  426.56
0765349 | $10.50 |  37.0 |    0.0 | $  0.00 | $  388.50
0034645 | $12.25 |  45.0 |    5.0 | $ 91.88 | $  581.88
0127615 | $ 8.35 |   0.0 |    0.0 | $  0.00 | $    0.00