fork 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. printf ("\n*** Pay Calculator ***\n\n");
  44.  
  45. // process each employee one at a time
  46. for (i = 0; i < SIZE; i++)
  47. {
  48.  
  49. // hours worked for employee
  50. printf("%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 normalPay and overtimePay with overtime
  59. normalPay[i] = STD_HOURS * wageRate[i];
  60. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  61. }
  62. else // no OT
  63. {
  64. overtimeHrs[i] = 0;
  65.  
  66. //calculate normalPay and overtimePay without overtime
  67. normalPay[i] = hours[i] * wageRate[i];
  68. overtimePay[i] = 0;
  69. }
  70.  
  71. // calculate Gross Pay
  72. grossPay[i] = normalPay[i] + overtimePay[i];
  73. }
  74.  
  75. // print table header
  76. printf("\n%-10s %-10s %-10s %-12s %-12s %-12s %-12s\n",
  77. "Clock #", "Wage", "Hours", "OT Hours",
  78. "Normal Pay", "OT Pay", "Gross Pay");
  79.  
  80. printf("-------------------------------------------------------------------------------\n");
  81.  
  82.  
  83. for (i = 0; i < SIZE; i++)
  84. {
  85. // print employee information from arrays
  86. printf("%-10ld %-10.2f %-10.2f %-12.2f %-12.2f %-12.2f %-12.2f\n",
  87. clockNumber[i],
  88. wageRate[i],
  89. hours[i],
  90. overtimeHrs[i],
  91. normalPay[i],
  92. overtimePay[i],
  93. grossPay[i]);
  94. }
  95.  
  96. return(0);
  97. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

98401: 526488: 765349: 34645: 127615: 
Clock #    Wage       Hours      OT Hours     Normal Pay   OT Pay       Gross Pay   
-------------------------------------------------------------------------------
98401      10.60      51.00      11.00        424.00       174.90       598.90      
526488     9.75       42.50      2.50         390.00       36.56        426.56      
765349     10.50      37.00      0.00         388.50       0.00         388.50      
34645      12.25      45.00      5.00         490.00       91.88        581.88      
127615     8.35       0.00       0.00         0.00         0.00         0.00