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.0f // normal work week hours before overtime
  21. #define OT_RATE 1.5f // 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.60f, 9.75f, 10.50f, 12.25f, 8.35f};
  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. // C-style input using scanf, replacing C++'s cin
  42. printf("Enter the hours worked for employee %ld: ", clockNumber[i]);
  43. scanf("%f", &hours[i]);
  44.  
  45. // Calculate overtime and gross pay for the employee
  46. if (hours[i] > STD_HOURS) {
  47. overtimeHrs[i] = hours[i] - STD_HOURS;
  48. normalPay[i] = STD_HOURS * wageRate[i];
  49. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  50. grossPay[i] = normalPay[i] + overtimePay[i];
  51. } else { // No overtime
  52. overtimeHrs[i] = 0.0f;
  53. overtimePay[i] = 0.0f;
  54. normalPay[i] = hours[i] * wageRate[i];
  55. grossPay[i] = normalPay[i];
  56. }
  57. }
  58.  
  59. // Print a nice table header
  60. printf("\n\n---------------------------------------------------------------\n");
  61. printf("Clock # | Wage | Hours | OT Hrs | OT Pay | Gross Pay\n");
  62. printf("---------------------------------------------------------------\n");
  63.  
  64. // Loop to print employee data
  65. for (i = 0; i < SIZE; i++) {
  66. // Print all the employees using a dedicated function
  67. printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  68. }
  69.  
  70. return 0;
  71. }
  72.  
  73. // Function definition for printEmp
  74. void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay) {
  75. printf("%07ld | $%5.2f | %5.1f | %6.1f | $%6.2f | $%8.2f\n",
  76. clockNumber, wageRate, hours, overtimeHrs, overtimeHrs * wageRate * OT_RATE, grossPay);
  77. }
Success #stdin #stdout 0.01s 5320KB
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