fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 22-Feb-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 // 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 and variables
  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
  30. float normalPay[SIZE]; // pay for regular hours
  31. float overtimeHrs[SIZE]; // overtime hours
  32. float overtimePay[SIZE]; // overtime pay
  33. float grossPay[SIZE]; // total pay
  34. int i;
  35.  
  36. printf("\n*** Pay Calculator ***\n\n");
  37.  
  38. // Input hours worked for each employee
  39. for (i = 0; i < SIZE; i++)
  40. {
  41. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  42. scanf("%f", &hours[i]);
  43.  
  44. // Calculate overtime and normal pay
  45. if (hours[i] > STD_HOURS)
  46. {
  47. overtimeHrs[i] = hours[i] - STD_HOURS;
  48. normalPay[i] = STD_HOURS * wageRate[i];
  49. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  50. }
  51. else
  52. {
  53. overtimeHrs[i] = 0;
  54. normalPay[i] = hours[i] * wageRate[i];
  55. overtimePay[i] = 0;
  56. }
  57.  
  58. // Calculate gross pay
  59. grossPay[i] = normalPay[i] + overtimePay[i];
  60. }
  61.  
  62. // Print header
  63. printf("\n%-10s %-10s %-10s %-10s %-10s %-10s\n",
  64. "Clock #", "Hours", "Rate", "Normal", "OT Hrs", "Gross");
  65. printf("------------------------------------------------------------\n");
  66.  
  67. // Print employee info
  68. for (i = 0; i < SIZE; i++)
  69. {
  70. printf("%-10ld %-10.2f $%-9.2f $%-9.2f %-10.2f $%-9.2f\n",
  71. clockNumber[i], hours[i], wageRate[i], normalPay[i],
  72. overtimeHrs[i], grossPay[i]);
  73. }
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5288KB
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      Rate       Normal     OT Hrs     Gross     
------------------------------------------------------------
98401      51.00      $10.60     $424.00    11.00      $598.90   
526488     42.50      $9.75      $390.00    2.50       $426.56   
765349     37.00      $10.50     $388.50    0.00       $388.50   
34645      45.00      $12.25     $490.00    5.00       $581.88   
127615     0.00       $8.35      $0.00      0.00       $0.00