fork download
  1. #//*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Seth Hin
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: February 19, 2026
  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.  
  17. #include <stdio.h>
  18.  
  19. // constants to use
  20. #define SIZE 5 // number of employees to process
  21. #define STD_HOURS 40.0 // normal work week hours before overtime
  22. #define OT_RATE 1.5 // time and half overtime setting
  23.  
  24. int main()
  25. {
  26.  
  27.  
  28.  
  29.  
  30. // unique employee identifier
  31. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  32.  
  33. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  34. float hours [SIZE]; // hours worked in a given week
  35. int i; // loop and array index
  36. float normalPay [SIZE]; // normal weekly pay without any overtime
  37. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  38. float overtimePay [SIZE]; // overtime pay for a given week
  39.  
  40. // hourly pay for each employee
  41. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  42.  
  43. // totals
  44. float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
  45.  
  46. printf ("\n*** Pay Calculator ***\n\n");
  47.  
  48. // process each employee one at a time
  49. for (i = 0; i < SIZE; i++)
  50. {
  51.  
  52. // hours worked for employee
  53.  
  54. printf("%ld: ", clockNumber[i]);
  55. scanf("%f", &hours[i]);
  56.  
  57. // calculate overtime and gross pay for employee
  58.  
  59. if (hours[i] >= STD_HOURS)
  60. {
  61. overtimeHrs[i] = hours[i] - STD_HOURS;
  62.  
  63. //calculate normalPay and overtimePay with overtime
  64.  
  65. normalPay[i] = STD_HOURS * wageRate[i];
  66. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  67. }
  68. else // no OT
  69. {
  70. overtimeHrs[i] = 0;
  71.  
  72. //calculate normalPay and overtimePay without overtime
  73.  
  74. normalPay[i] = hours[i] * wageRate[i];
  75. overtimePay[i] = 0;
  76. }
  77.  
  78. // calculate Gross Pay
  79.  
  80. grossPay[i] = normalPay[i] + overtimePay[i];
  81.  
  82. // accumlative totals
  83.  
  84. totalWage += wageRate[i];
  85. totalHours += hours[i];
  86. totalOT += overtimeHrs[i];
  87. totalGross += grossPay[i];
  88. }
  89.  
  90. // print table header
  91.  
  92. printf("\n%-8s %10s %10s %10s %12s\n",
  93. "Clock#", "Wage", "Hours", "OT", "Gross");
  94. printf("-----------------------------------------------------------------\n");
  95.  
  96.  
  97.  
  98.  
  99. for (i = 0; i < SIZE; i++)
  100. {
  101. // print employee information from arrays
  102.  
  103. printf("%-8ld %10.2f %10.2f %10.2f %12.2f\n",
  104. clockNumber[i],
  105. wageRate[i],
  106. hours[i],
  107. overtimeHrs[i],
  108. grossPay[i]);
  109. }
  110. printf("-----------------------------------------------------------------\n");
  111.  
  112. {
  113.  
  114. // totals row
  115. printf("%-8s %10.2f %10.2f %10.2f %12.2f\n",
  116. "Total",
  117. totalWage, totalHours, totalOT, totalGross);
  118.  
  119. // averages row
  120. printf("%-8s %10.2f %10.2f %10.2f %12.2f\n",
  121. "Average",
  122. totalWage / SIZE,
  123. totalHours / SIZE,
  124. totalOT / SIZE,
  125. totalGross / SIZE);
  126.  
  127. } // end for loop
  128.  
  129. return(0);
  130. }
Success #stdin #stdout 0s 5292KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

98401: 526488: 765349: 34645: 127615: 
Clock#         Wage      Hours         OT        Gross
-----------------------------------------------------------------
98401         10.60      51.00      11.00       598.90
526488         9.75      42.50       2.50       426.56
765349        10.50      37.00       0.00       388.50
34645         12.25      45.00       5.00       581.88
127615         8.35       0.00       0.00         0.00
-----------------------------------------------------------------
Total         51.45     175.50      18.50      1995.84
Average       10.29      35.10       3.70       399.17