fork(2) download
  1. #//*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Seth Hin
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: February 18, 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. printf("%ld: ", clockNumber[i]);
  54. scanf("%f", &hours[i]);
  55.  
  56. // calculate overtime and gross pay for employee
  57. if (hours[i] >= STD_HOURS)
  58. {
  59. overtimeHrs[i] = hours[i] - STD_HOURS;
  60.  
  61. //calculate normalPay and overtimePay with overtime
  62. normalPay[i] = STD_HOURS * wageRate[i];
  63. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  64. }
  65. else // no OT
  66. {
  67. overtimeHrs[i] = 0;
  68.  
  69. //calculate normalPay and overtimePay without overtime
  70. normalPay[i] = hours[i] * wageRate[i];
  71. overtimePay[i] = 0;
  72. }
  73.  
  74. // calculate Gross Pay
  75. grossPay[i] = normalPay[i] + overtimePay[i];
  76.  
  77. // accumlative totals
  78. totalWage += wageRate[i];
  79. totalHours += hours[i];
  80. totalOT += overtimeHrs[i];
  81. totalGross += grossPay[i];
  82. }
  83.  
  84. // print table header
  85. printf("\nClock#\tWage#\tHours\tOT\tGross\n");
  86. printf("--------------\t---------\t--------\t-------\t-----------\n");
  87.  
  88.  
  89.  
  90.  
  91. for (i = 0; i < SIZE; i++)
  92. {
  93. // print employee information from arrays
  94. printf("%06ld\t%.2f\t%.1f\t%.1f\t%.2f\n",
  95. clockNumber[i],
  96. wageRate[i],
  97. hours[i],
  98. overtimeHrs[i],
  99. grossPay[i]);
  100. }
  101. printf("--------------\t---------\t--------\t-------\t-----------\n");
  102.  
  103. // totals row
  104. printf("Total\t%.2f\t%.1f\t%.1f\t%.2f\n",
  105. totalWage, totalHours, totalOT, totalGross);
  106.  
  107. // averages row
  108. printf("Average\t%.2f\t%.1f\t%.1f\t%.2f\n",
  109. totalWage/SIZE,
  110. totalHours/SIZE,
  111. totalOT/SIZE,
  112. totalGross/SIZE);
  113. return(0);
  114. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***

98401: 526488: 765349: 34645: 127615: 
Clock#	Wage#	Hours	OT	Gross
--------------	---------	--------	-------	-----------
098401	10.60	-nan	0.0	-nan
526488	9.75	0.0	0.0	0.00
765349	10.50	-0.0	0.0	-0.00
034645	12.25	0.0	0.0	0.00
127615	8.35	0.0	0.0	0.00
--------------	---------	--------	-------	-----------
Total	51.45	-nan	0.0	-nan
Average	10.29	-nan	0.0	-nan