fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Seth Hin
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: February 17, 2026
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with formatted totals
  13. // and averages printed to the screen.
  14. //
  15. //********************************************************
  16.  
  17. #include <stdio.h>
  18.  
  19. // constants to use
  20. #define SIZE 5
  21. #define STD_HOURS 40.0
  22. #define OT_RATE 1.5
  23.  
  24. int main()
  25. {
  26. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  27.  
  28. float grossPay [SIZE];
  29. float hours [SIZE];
  30. int i;
  31. float normalPay [SIZE];
  32. float overtimeHrs[SIZE];
  33. float overtimePay [SIZE];
  34.  
  35. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  36.  
  37. // *** ADDED BY STUDENT (Totals) ***
  38. float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
  39.  
  40. printf ("\n*** Pay Calculator ***\n\n");
  41.  
  42. for (i = 0; i < SIZE; i++)
  43. {
  44.  
  45. // TODO - Prompt and Read in hours worked for employee
  46. // *** ADDED BY STUDENT ***
  47. printf("Enter hours worked for employee %06ld: ", clockNumber[i]);
  48. scanf("%f", &hours[i]);
  49.  
  50. if (hours[i] >= STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS;
  53.  
  54. // TODO: Calculate arrays normalPay and overtimePay with overtime
  55. // *** ADDED BY STUDENT ***
  56. normalPay[i] = STD_HOURS * wageRate[i];
  57. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  58. }
  59. else
  60. {
  61. overtimeHrs[i] = 0;
  62.  
  63. // TODO: Calculate arrays normalPay and overtimePay without overtime
  64. // *** ADDED BY STUDENT ***
  65. normalPay[i] = hours[i] * wageRate[i];
  66. overtimePay[i] = 0;
  67. }
  68.  
  69. grossPay[i] = normalPay[i] + overtimePay[i];
  70.  
  71. // *** ADDED BY STUDENT (Accumulate totals) ***
  72. totalWage += wageRate[i];
  73. totalHours += hours[i];
  74. totalOT += overtimeHrs[i];
  75. totalGross += grossPay[i];
  76. }
  77.  
  78. // TODO: Print formatted table header
  79. // *** ADDED BY STUDENT ***
  80. printf("\nClock#\tWage#\tHours\tOT\tGross\n");
  81. printf("--------------\t---------\t--------\t-------\t-----------\n");
  82.  
  83. for (i = 0; i < SIZE; i++)
  84. {
  85. // TODO: Print employee information from your arrays
  86. // *** ADDED BY STUDENT ***
  87. printf("%06ld\t%.2f\t%.1f\t%.1f\t%.2f\n",
  88. clockNumber[i],
  89. wageRate[i],
  90. hours[i],
  91. overtimeHrs[i],
  92. grossPay[i]);
  93. }
  94.  
  95. printf("--------------\t---------\t--------\t-------\t-----------\n");
  96.  
  97. // *** ADDED BY STUDENT (Totals row) ***
  98. printf("Total\t%.2f\t%.1f\t%.1f\t%.2f\n",
  99. totalWage, totalHours, totalOT, totalGross);
  100.  
  101. // *** ADDED BY STUDENT (Average row) ***
  102. printf("Average\t%.2f\t%.1f\t%.1f\t%.2f\n",
  103. totalWage/SIZE,
  104. totalHours/SIZE,
  105. totalOT/SIZE,
  106. totalGross/SIZE);
  107.  
  108. return(0);
  109. }
  110.  
Success #stdin #stdout 0.01s 5320KB
stdin
51.0   
42.5   
37.0   
45.0   
0.0  
stdout
*** Pay Calculator ***

Enter hours worked for employee 098401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 034645: Enter hours worked for employee 127615: 
Clock#	Wage#	Hours	OT	Gross
--------------	---------	--------	-------	-----------
098401	10.60	51.0	11.0	598.90
526488	9.75	42.5	2.5	426.56
765349	10.50	37.0	0.0	388.50
034645	12.25	45.0	5.0	581.88
127615	8.35	0.0	0.0	0.00
--------------	---------	--------	-------	-----------
Total	51.45	175.5	18.5	1995.84
Average	10.29	35.1	3.7	399.17