fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: MARTIN CLYTON MAYANJA
  6. //
  7. // Class: C Programming, Spring,2026
  8. //
  9. // Date: 18FEBUARY2026
  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.  
  28. // Declare variables needed for the program
  29. // Recommend an array for clock, wage, hours,
  30. // ... and overtime hours and gross.
  31. // Recommend arrays also for normal pay and overtime pay
  32. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  33.  
  34. // unique employee identifier
  35. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  36.  
  37. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  38. float hours [SIZE]; // hours worked in a given week
  39. int i; // loop and array index
  40. float normalPay [SIZE]; // normal weekly pay without any overtime
  41. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  42. float overtimePay [SIZE]; // overtime pay for a given week
  43.  
  44. // hourly pay for each employee
  45. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  46.  
  47. printf ("\n*** Pay Calculator ***\n\n");
  48.  
  49. // Process each employee one at a time
  50. for (i = 0; i < SIZE; i++)
  51. {
  52.  
  53. // TODO - Prompt and Read in hours worked for employee
  54.  
  55. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  56. scanf("%f", &hours[i]);
  57.  
  58. // Calculate overtime and gross pay for employee
  59. if (hours[i] >= STD_HOURS)
  60. {
  61. overtimeHrs[i] = hours[i] - STD_HOURS;
  62. // TODO: Calculate arrays normalPay and overtimePay with overtime
  63.  
  64. normalPay[i] = STD_HOURS * wageRate[i];
  65. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  66.  
  67. }
  68. else // no OT
  69. {
  70. overtimeHrs[i] = 0;
  71. // TODO: Calculate arrays normalPay and overtimePay without overtime
  72.  
  73. normalPay[i] = hours[i] * wageRate[i];
  74. overtimePay[i] = 0;
  75.  
  76. }
  77.  
  78. // Calculate Gross Pay
  79. grossPay[i] = normalPay[i] + overtimePay[i];
  80. }
  81.  
  82. // TODO: Print a nice table header
  83. printf("\n--------------------------------------------------\n");
  84. printf("Clock# Hours Wage OT Hours Gross Pay\n");
  85. printf("----------------------------------------------------\n");
  86.  
  87.  
  88. // Now that we have all the information in our arrays, we can
  89. // Access each employee and print to screen or file
  90.  
  91. for (i = 0; i < SIZE; i++)
  92. {
  93.  
  94. printf("%-10ld %-9.2f %-8.2f %-12.2f %-10.2f\n",
  95. clockNumber[i],
  96. hours[i],
  97. wageRate[i],
  98. overtimeHrs[i],
  99. grossPay[i]);
  100.  
  101.  
  102. // TODO: Print employee information from your arrays
  103. printf("------------------------------------------------\n");
  104.  
  105. }
  106.  
  107. return(0);
  108. }
Success #stdin #stdout 0.01s 5276KB
stdin
51.0
42.5
37.0
45.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#     Hours     Wage     OT Hours     Gross Pay
----------------------------------------------------
98401      51.00     10.60    11.00        598.90    
------------------------------------------------
526488     42.50     9.75     2.50         426.56    
------------------------------------------------
765349     37.00     10.50    0.00         388.50    
------------------------------------------------
34645      45.00     12.25    5.00         581.88    
------------------------------------------------
127615     0.00      8.35     0.00         0.00      
------------------------------------------------