fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Patrick Andrade
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: September 28, 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. // unique employee identifier
  28. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  29.  
  30. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  31. float hours [SIZE]; // hours worked in a given week
  32. int i; // loop and array index
  33. float normalPay [SIZE]; // normal weekly pay without any overtime
  34. float overtimeHrs [SIZE]; // overtime hours worked in a given week
  35. float overtimePay [SIZE]; // overtime pay for a given week
  36.  
  37. // hourly pay for each employee
  38. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  39.  
  40. // optional challenge - running totals for each column
  41. float totalWage = 0; // sum of all wage rates
  42. float totalHours = 0; // sum of all hours worked
  43. float totalOT = 0; // sum of all overtime hours
  44. float totalGross = 0; // sum of all gross pay
  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. // Prompt and read in hours worked for employee
  53. printf ("Enter the number of hours employee %06li worked: ",
  54. clockNumber[i]);
  55. scanf ("%f", &hours[i]);
  56.  
  57. // Calculate overtime and gross pay for employee
  58. if (hours[i] >= STD_HOURS)
  59. {
  60. overtimeHrs[i] = hours[i] - STD_HOURS;
  61. normalPay[i] = STD_HOURS * wageRate[i];
  62. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  63. }
  64. else // no OT
  65. {
  66. overtimeHrs[i] = 0;
  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. // optional challenge - add this employee to the totals
  75. totalWage += wageRate[i];
  76. totalHours += hours[i];
  77. totalOT += overtimeHrs[i];
  78. totalGross += grossPay[i];
  79. }
  80.  
  81. // Print a nice table header
  82. printf ("\n");
  83. printf ("---------------------------------------------\n");
  84. printf (" Clock# Wage Hours OT Gross\n");
  85. printf ("---------------------------------------------\n");
  86.  
  87. // Now that we have all the information in our arrays, we can
  88. // access each employee and print to screen
  89. for (i = 0; i < SIZE; i++)
  90. {
  91. printf (" %06li %6.2f %6.1f %5.1f %9.2f\n",
  92. clockNumber[i], wageRate[i], hours[i],
  93. overtimeHrs[i], grossPay[i]);
  94. }
  95.  
  96. // optional challenge - print totals and averages
  97. printf ("---------------------------------------------\n");
  98. printf (" Total %6.2f %6.1f %5.1f %9.2f\n",
  99. totalWage, totalHours, totalOT, totalGross);
  100. printf (" Average %6.2f %6.1f %5.1f %9.2f\n",
  101. totalWage / SIZE, totalHours / SIZE,
  102. totalOT / SIZE, totalGross / SIZE);
  103.  
  104. return(0);
  105. }
Success #stdin #stdout 0s 5256KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter the number of hours employee 098401 worked: Enter the number of hours employee 526488 worked: Enter the number of hours employee 765349 worked: Enter the number of hours employee 034645 worked: Enter the number of hours employee 127615 worked: 
---------------------------------------------
  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