fork download
  1. //
  2. // Assignment 4 - Arrays
  3. //
  4. // Name: Henri Biqiku
  5. //
  6. // Class: C Programming, Fall 2026
  7. //
  8. // Date: Oct 4, 2026
  9. //
  10. // Description: Program which determines overtime and
  11. // gross pay for a set of employees with outputs sent
  12. // to standard output (the screen).
  13. //
  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. int main()
  24. {
  25. // Declare variables needed for the program
  26. // Recommend an array for clock, wage, hours,
  27. // ... and overtime hours and gross.
  28. // Recommend arrays also for normal pay and overtime pay
  29. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  30.  
  31. // unique employee identifier
  32. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  33.  
  34. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  35. float hours[SIZE]; // hours worked in a given week
  36. int i; // loop and array index
  37. float normalPay[SIZE]; // normal weekly pay without any overtime
  38. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  39. float overtimePay[SIZE]; // overtime pay for a given week
  40.  
  41. // hourly pay for each employee
  42. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  43.  
  44. printf("\n*** Pay Calculator ***\n\n");
  45.  
  46. // Process each employee one at a time
  47. for (i = 0; i < SIZE; i++)
  48. {
  49. // Prompt and read in hours worked for employee
  50. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  51. scanf("%f", &hours[i]);
  52.  
  53. // Calculate overtime and gross pay for employee
  54. if (hours[i] >= STD_HOURS)
  55. {
  56. overtimeHrs[i] = hours[i] - STD_HOURS;
  57.  
  58. // Calculate normal pay and overtime pay
  59. normalPay[i] = wageRate[i] * STD_HOURS;
  60. overtimePay[i] = wageRate[i] * OT_RATE * overtimeHrs[i];
  61. }
  62. else // no OT
  63. {
  64. overtimeHrs[i] = 0;
  65.  
  66. // Calculate normal pay and overtime pay without overtime
  67. normalPay[i] = wageRate[i] * hours[i];
  68. overtimePay[i] = 0;
  69. }
  70.  
  71. // Calculate Gross Pay
  72. grossPay[i] = normalPay[i] + overtimePay[i];
  73. }
  74.  
  75. // Print a nice table header
  76. printf("\n");
  77. printf(" Clock # Wage Hours Normal Pay OT Hours OT Pay Gross Pay\n");
  78. printf("---------------------------------------------------------------------\n");
  79.  
  80. // Now that we have all the information in our arrays, we can
  81. // Access each employee and print to screen or file
  82. for (i = 0; i < SIZE; i++)
  83. {
  84. // Print employee information from your arrays
  85. printf("%7ld %6.2f %5.1f %8.2f %6.1f %7.2f %8.2f\n",
  86. clockNumber[i],
  87. wageRate[i],
  88. hours[i],
  89. normalPay[i],
  90. overtimeHrs[i],
  91. overtimePay[i],
  92. grossPay[i]);
  93. }
  94.  
  95. return(0);
  96. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***

Enter hours worked for employee 98401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 34645: Enter hours worked for employee 127615: 
 Clock #   Wage   Hours   Normal Pay   OT Hours   OT Pay   Gross Pay
---------------------------------------------------------------------
  98401   10.60   -0.0       -0.00       0.0       0.00      -0.00
 526488    9.75    0.0        0.00       0.0       0.00       0.00
 765349   10.50    0.0        0.00       0.0       0.00       0.00
  34645   12.25    0.0        0.00       0.0       0.00       0.00
 127615    8.35    0.0        0.00       0.0       0.00       0.00