fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Tina Gayle-Campbell
  6. //
  7. // Class: C Programming, Fall, 2026
  8. //
  9. // Date: October 9, 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. #include <stdio.h>
  20.  
  21. // constants to use
  22. #define SIZE 5 // number of employees to process
  23. #define STD_HOURS 40.0 // normal work week hours before overtime
  24. #define OT_RATE 1.5 // time and half overtime setting
  25.  
  26. int main()
  27. {
  28. // unique employee identifier
  29. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  30.  
  31. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  32. float hours [SIZE]; // hours worked in a given week
  33. int i; // loop and array index
  34. float normalPay [SIZE]; // normal weekly pay without any overtime
  35. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  36. float overtimePay [SIZE]; // overtime pay for a given week
  37.  
  38. // hourly pay for each employee
  39. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  40.  
  41. printf ("\n*** Pay Calculator ***\n\n");
  42.  
  43. // Process each employee one at a time
  44. for (i = 0; i < SIZE; i++)
  45. {
  46. // Prompt and Read in hours worked for employee
  47. printf("Enter hours worked for employee %06ld: ", clockNumber[i]);
  48. scanf("%f", &hours[i]);
  49.  
  50. // Calculate overtime and gross pay for employee
  51. if (hours[i] > STD_HOURS)
  52. {
  53. overtimeHrs[i] = hours[i] - STD_HOURS;
  54. normalPay[i] = STD_HOURS * wageRate[i];
  55. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  56. }
  57. else // no OT
  58. {
  59. overtimeHrs[i] = 0.0;
  60. normalPay[i] = hours[i] * wageRate[i];
  61. overtimePay[i] = 0.0;
  62. }
  63.  
  64. // Calculate Gross Pay
  65. grossPay[i] = normalPay[i] + overtimePay[i];
  66. }
  67.  
  68. // Print a nice table header
  69. printf("\n---------------------------------------------------------------------------------\n");
  70. printf("%-10s %-10s %-8s %-10s %-10s %-12s %-10s\n",
  71. "Clock#", "Wage", "Hours", "OT Hours", "Reg Pay", "OT Pay", "Gross Pay");
  72. printf("---------------------------------------------------------------------------------\n");
  73.  
  74. // Access each employee and print to screen
  75. for (i = 0; i < SIZE; i++)
  76. {
  77. printf("%-10ld $%8.2f %8.1f %10.1f $%9.2f $%11.2f $%9.2f\n",
  78. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i],
  79. normalPay[i], overtimePay[i], grossPay[i]);
  80. }
  81. printf("---------------------------------------------------------------------------------\n");
  82.  
  83. return 0;
  84. }
  85.  
Success #stdin #stdout 0s 5316KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee 098401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 034645: Enter hours worked for employee 127615: 
---------------------------------------------------------------------------------
Clock#     Wage       Hours    OT Hours   Reg Pay    OT Pay       Gross Pay 
---------------------------------------------------------------------------------
98401      $   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
34645      $   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
---------------------------------------------------------------------------------