fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Neftalia Cruz>
  6. //
  7. // Class: C Programming, <Fall, 2026>
  8. //
  9. // Date: <September 30, 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. // Declare variables needed for the program
  29. // Recommend an array for clock, wage, hours,
  30. // ... and overtime hours and gross.
  31. // Recommend arrays also for normal pay and overtime pay
  32. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  33.  
  34. // unique employee identifier
  35. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  36.  
  37. float grossPay [SIZE]; // weekly gross pay - normal pay +overtime pay
  38. float HOURS [SIZE]; // hours worked in a given week
  39. int i; // loop and array index
  40. float normalPay [SIZE]; // normal weekly pay without any overtime
  41. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  42. float overtimePay [SIZE]; // overtime pay for a given week
  43.  
  44. // hourly pay for each employee
  45. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  46.  
  47. float wageSum, hoursSum, otSum, grossSum;
  48.  
  49. printf ("\n*** Pay Calculator ***\n\n");
  50.  
  51. // Process each employee one at a time
  52. for (i = 0; i < SIZE; i++)
  53. {
  54. wageSum += wageRate[i];
  55.  
  56. printf("enter hours worked for employee %ld", clockNumber[i]);
  57. scanf("%f", &HOURS[i]);
  58.  
  59. hoursSum += HOURS[i];
  60.  
  61. // Calculate overtime and gross pay for employee
  62. if (HOURS[i] >= STD_HOURS)
  63. {
  64. overtimeHrs[i] = HOURS[i] - STD_HOURS;
  65. otSum += overtimeHrs[i];
  66.  
  67. normalPay[i] = STD_HOURS * wageRate[i];
  68. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  69.  
  70. }
  71. else // no OT
  72. {
  73. overtimeHrs[i] = 0;
  74. normalPay[i] = HOURS[i] * wageRate[i];
  75. overtimePay[i] = 0;
  76.  
  77. }
  78.  
  79. // Calculate Gross Pay
  80. grossPay[i] = normalPay[i] + overtimePay[i];
  81. grossSum += grossPay[i];
  82. }
  83.  
  84.  
  85. printf("\n");
  86. printf("-----------------------------------------\n");
  87. printf(" clock # Wage HOURS OT Gross\n");
  88. printf("-----------------------------------------\n");
  89.  
  90. // Now that we have all the information in our arrays, we can
  91. // Access each employee and print to screen or file
  92. for (i = 0; i < SIZE; i++)
  93. {
  94. //
  95. printf(" %06ld %5.2f %5.1f %6.1f %10.2f\n",
  96. clockNumber[i],
  97. wageRate[i],
  98. HOURS[i],
  99. overtimeHrs[i],
  100. grossPay[i]);
  101. }
  102.  
  103. printf(" -----------------------------------------\n");
  104. printf(" Total %5.2f %5.2f %6.1f %10.2f\n",
  105. wageSum,
  106. hoursSum,
  107. otSum,
  108. grossSum);
  109. printf(" Average %5.2f %5.2f %6.1f %10.2f\n",
  110. wageSum / SIZE,
  111. hoursSum / SIZE,
  112. otSum / SIZE,
  113. grossSum / SIZE);
  114.  
  115. return(0);
  116. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

enter hours worked for employee 98401enter hours worked for employee 526488enter hours worked for employee 765349enter hours worked for employee 34645enter 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.50      18.5       1995.84
   Average    10.29    35.10       3.7        399.17