fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Carlos Dominguez
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 02/21/2026 --------------More snow in the horizon
  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 variables needed for the program
  27. // Recommend an array for clock, wage, hours,
  28. // ... and overtime hours and gross.
  29. // Recommend arrays also for normal pay and overtime pay
  30. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  31.  
  32. // unique employee identifier
  33. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  34.  
  35. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  36. float hours [SIZE]; // hours worked in a given week
  37. int i; // loop and array index
  38. float normalPay [SIZE]; // normal weekly pay without any overtime
  39. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  40. float overtimePay [SIZE]; // overtime pay for a given week
  41.  
  42. // hourly pay for each employee
  43. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  44.  
  45. printf ("\n*** Pay Calculator ***\n\n");
  46.  
  47. // Process each employee one at a time
  48. for (i = 0; i < SIZE; i++)
  49. {
  50.  
  51. // Prompt and read hours for each employee
  52. printf("\nEnter the number of hours worked for employee %ld: ",
  53. clockNumber[i]);
  54. scanf("%f", &hours[i]);
  55.  
  56. // Calculate overtime and gross pay for employee
  57. if (hours[i] >= STD_HOURS)
  58. {
  59. // Employee worked overtime
  60. overtimeHrs[i] = hours[i] - STD_HOURS;
  61.  
  62. // Normal pay is capped at STD_HOURS
  63. normalPay[i] = STD_HOURS * wageRate[i];
  64.  
  65. // Overtime pay uses OT_RATE multiplier
  66. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  67.  
  68. }
  69. else // no OT
  70. {
  71. overtimeHrs[i] = 0;
  72. // All hours are normal hours
  73. normalPay[i] = hours[i] * wageRate[i];
  74.  
  75. // No overtime pay
  76. overtimePay[i] = 0.0;
  77.  
  78. }
  79.  
  80. // Calculate Gross Pay
  81. grossPay[i] = normalPay[i] + overtimePay[i];
  82. }
  83. //Print a nice table header
  84. printf("\n-----------------------------------------------------------");
  85. printf("\nClock# Wage Hours OT Normal OT Pay Gross\n");
  86. printf("-----------------------------------------------------------\n");
  87. // Now that we have all the information in our arrays, we can
  88. // Access each employee and print to screen or file
  89.  
  90. // Output Loop — Print Employee Payroll Data
  91. for (i = 0; i < SIZE; i++)
  92. {
  93. //Print employee information from your arrays
  94. printf("%06ld %5.2f %5.1f %4.1f %7.2f %7.2f %7.2f\n",
  95. clockNumber[i],
  96. wageRate[i],
  97. hours[i],
  98. overtimeHrs[i],
  99. normalPay[i],
  100. overtimePay[i],
  101. grossPay[i]);
  102.  
  103. }
  104.  
  105. return(0);
  106. }
Success #stdin #stdout 0s 5328KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


Enter the number of hours worked for employee 98401: 
Enter the number of hours worked for employee 526488: 
Enter the number of hours worked for employee 765349: 
Enter the number of hours worked for employee 34645: 
Enter the number of hours worked for employee 127615: 
-----------------------------------------------------------
Clock#     Wage   Hours   OT   Normal   OT Pay   Gross
-----------------------------------------------------------
098401   10.60   51.0  11.0   424.00   174.90   598.90
526488    9.75   42.5   2.5   390.00    36.56   426.56
765349   10.50   37.0   0.0   388.50     0.00   388.50
034645   12.25   45.0   5.0   490.00    91.88   581.88
127615    8.35    0.0   0.0     0.00     0.00     0.00