fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Felix Henriquez>
  6. //
  7. // Class: C Programming, <Fall 2025>
  8. //
  9. // Date: <10/5/2025>
  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. // Declare arrays for employee data
  27. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  28. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  29. float hours[SIZE]; // hours worked in a given week
  30. float overtimeHrs[SIZE]; // overtime hours worked
  31. float grossPay[SIZE]; // weekly gross pay
  32.  
  33. // Variables for totals and averages
  34. float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
  35. float avgWage, avgHours, avgOT, avgGross;
  36. int i; // loop counter
  37.  
  38. printf("*** Pay Calculator ***\n\n");
  39.  
  40. // Prompt for hours worked for each employee
  41. for (i = 0; i < SIZE; i++)
  42. {
  43. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  44. scanf("%f", &hours[i]);
  45. }
  46.  
  47. // Calculate overtime and gross pay for each employee
  48. for (i = 0; i < SIZE; i++)
  49. {
  50. // Calculate overtime hours
  51. if (hours[i] > STD_HOURS)
  52. {
  53. overtimeHrs[i] = hours[i] - STD_HOURS;
  54. }
  55. else
  56. {
  57. overtimeHrs[i] = 0;
  58. }
  59.  
  60. // Calculate gross pay
  61. if (hours[i] <= STD_HOURS)
  62. {
  63. // No overtime - straight pay
  64. grossPay[i] = hours[i] * wageRate[i];
  65. }
  66. else
  67. {
  68. // With overtime - normal pay for 40 hours + OT pay for extra hours
  69. grossPay[i] = (STD_HOURS * wageRate[i]) +
  70. (overtimeHrs[i] * wageRate[i] * OT_RATE);
  71. }
  72. }
  73.  
  74. // Calculate totals
  75. for (i = 0; i < SIZE; i++)
  76. {
  77. totalWage += wageRate[i];
  78. totalHours += hours[i];
  79. totalOT += overtimeHrs[i];
  80. totalGross += grossPay[i];
  81. }
  82.  
  83. // Calculate averages
  84. avgWage = totalWage / SIZE;
  85. avgHours = totalHours / SIZE;
  86. avgOT = totalOT / SIZE;
  87. avgGross = totalGross / SIZE;
  88.  
  89. // Print the header and table
  90. printf("\n-------------------------------------------------------------\n");
  91. printf(" Clock# Wage Hours OT Gross\n");
  92. printf("-------------------------------------------------------------\n");
  93.  
  94. for (i = 0; i < SIZE; i++)
  95. {
  96. // Print each employee's data with proper formatting
  97. // Clock# with leading zero, wage/hours/OT/gross with proper decimal places
  98. printf(" %06ld %5.2f %4.1f %4.1f %7.2f\n",
  99. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  100. }
  101.  
  102. // Print the totals line
  103. printf("--------------------------------------------\n");
  104. printf(" Total %5.2f %5.1f %5.1f %8.2f\n",
  105. totalWage, totalHours, totalOT, totalGross);
  106.  
  107. // Print the averages line
  108. printf(" Average %5.2f %5.1f %5.1f %8.2f\n",
  109. avgWage, avgHours, avgOT, avgGross);
  110.  
  111. return 0;
  112. }
Success #stdin #stdout 0s 5320KB
stdin
49.0
46.5
39.0
41.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee 98401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 34645: Enter hours worked for employee 127615: 
-------------------------------------------------------------
  Clock#   Wage   Hours    OT      Gross
-------------------------------------------------------------
  098401  10.60   49.0     9.0    567.10
  526488   9.75   46.5     6.5    485.06
  765349  10.50   39.0     0.0    409.50
  034645  12.25   41.0     1.0    508.38
  127615   8.35    0.0     0.0      0.00
--------------------------------------------
  Total   51.45  175.5    16.5   1970.04
  Average 10.29   35.1     3.3    394.01