fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Henri Biqiku
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: Oct 4, 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 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] = {
  34. 98401, 526488, 765349, 34645, 127615
  35. };
  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] = {
  46. 10.6, 9.75, 10.5, 12.25, 8.35
  47. };
  48.  
  49. printf("\n*** Pay Calculator ***\n\n");
  50.  
  51. // Process each employee one at a time
  52. for (i = 0; i < SIZE; i++)
  53. {
  54. // TODO - Prompt and Read in hours worked for employee
  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.  
  63. // TODO: Calculate arrays normalPay and overtimePay with overtime
  64. normalPay[i] = wageRate[i] * STD_HOURS;
  65. overtimePay[i] = wageRate[i] * OT_RATE * overtimeHrs[i];
  66. }
  67. else // no OT
  68. {
  69. overtimeHrs[i] = 0.0;
  70.  
  71. // TODO: Calculate arrays normalPay and overtimePay without overtime
  72. normalPay[i] = wageRate[i] * hours[i];
  73. overtimePay[i] = 0.0;
  74. }
  75.  
  76. // Calculate Gross Pay
  77. grossPay[i] = normalPay[i] + overtimePay[i];
  78. }
  79.  
  80. // TODO: Print a nice table header
  81. printf("--------------------------------------------------------------------------\n");
  82. printf(" Clock# Wage Hours OT Gross\n");
  83. printf("--------------------------------------------------------------------------\n");
  84.  
  85. // Now that we have all the information in our arrays, we can
  86. // Access each employee and print to screen or file
  87. for (i = 0; i < SIZE; i++)
  88. {
  89. // TODO: Print employee information from your arrays
  90. printf(" %06ld %5.2f %5.1f %6.1f %10.2f\n",
  91. clockNumber[i],
  92. wageRate[i],
  93. hours[i],
  94. overtimeHrs[i],
  95. grossPay[i]);
  96. }
  97.  
  98. return(0);
  99. }
Success #stdin #stdout 0s 5328KB
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#   Wage  Hours    OT       Gross
--------------------------------------------------------------------------
    098401  10.60   51.0    11.0      598.90
    526488   9.75   42.5     2.5      426.56
    765349  10.50   37.0     0.0      388.50
    034645  12.25   45.0     5.0      581.88
    127615   8.35    0.0     0.0        0.00