fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Joshua Lane
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: 10/01/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 // Standard array size
  21. #define STD_HOURS 40.0 // Standard hours worked before OT is met
  22. #define OT_RATE 1.5 // Added pay rate for hours classified as OT
  23.  
  24. int main()
  25. {
  26. // Establishes an array containing each employees clock number
  27. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  28.  
  29. float grossPay[SIZE]; // Total pay (STD + OT)
  30. float hours[SIZE]; // Total hours worked
  31. int i; // Variable for loops and array calculations
  32. float normalPay[SIZE]; // Pay from standard hourly work only
  33. float overtimeHrs[SIZE]; // Number of OT hours worked
  34. float overtimePay[SIZE]; // Pay from OT hourly work only
  35.  
  36. // Creates an array containing the hourly pay for each employee
  37. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  38.  
  39. printf("\n*** Pay Calculator ***\n\n");
  40.  
  41. // Loop to iterate through each employee and calculuate their grossPay
  42. for (i = 0; i < SIZE; i++)
  43. {
  44. // Prompt and read hours worked
  45. printf("Enter hours worked for employee:");
  46. scanf("%f", &hours[i]);
  47. printf("\n");
  48.  
  49. // Calculate overtime and gross pay for each employee created in the earlier array
  50. if (hours[i] > STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS; //Calculates # OT hours worked
  53. normalPay[i] = STD_HOURS * wageRate[i]; //Calculates STD work pay
  54. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE; //Calculates OT work pay
  55. }
  56. else
  57. {
  58. overtimeHrs[i] = 0; //If <= 40 hrs worked, OT hours must be = 0
  59. normalPay[i] = hours[i] * wageRate[i]; // Pay rate is then std hours * wage only
  60. overtimePay[i] = 0; // No overtime pay needed in this event
  61. }
  62.  
  63. // Calculate gross pay after normalPay and overtimePay have been stored to
  64. // the arrays for each employee in the earlier loops
  65. grossPay[i] = normalPay[i] + overtimePay[i];
  66.  
  67. } //End of employee wage data calculations loop
  68.  
  69. // Prints the table header, makes reading reporting easier
  70. printf("\n");
  71. printf("---------------------------------------------------------------\n");
  72. printf("Clock# Wage Hours OT Hours Gross Pay\n");
  73. printf("---------------------------------------------------------------\n");
  74.  
  75. // Loops through each employee, outputting their wage data
  76. for (i = 0; i < SIZE; ++i)
  77. {
  78. printf("%06d %5.2f %5.1f %8.2f %8.2f\n",
  79. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  80.  
  81. } // End employee data output loop
  82.  
  83. printf("---------------------------------------------------------------\n");
  84.  
  85. return 0;
  86. }
Success #stdin #stdout 0s 5328KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee:
Enter hours worked for employee:
Enter hours worked for employee:
Enter hours worked for employee:
Enter hours worked for employee:

---------------------------------------------------------------
Clock#     Wage     Hours     OT Hours     Gross Pay
---------------------------------------------------------------
098401     10.60     51.0        11.00       598.90
526488      9.75     42.5         2.50       426.56
765349     10.50     37.0         0.00       388.50
034645     12.25     45.0         5.00       581.88
127615      8.35      0.0         0.00         0.00
---------------------------------------------------------------