fork download
  1.  
  2.  
  3. #include <stdio.h>
  4.  
  5.  
  6. /* constants */
  7. #define NUM_EMPL 5
  8. #define OT_RATE 1.5f
  9. #define STD_HOURS 40.0f
  10.  
  11.  
  12.  
  13. float getHours (long clockNumber);
  14. void printData (long int clockNumber[], float wageRate[], float hours[],
  15. float overtime[], float gross[], int size);
  16.  
  17.  
  18.  
  19. int main()
  20. {
  21.  
  22. /* Variable Declarations */
  23.  
  24. long int clockNumber[NUM_EMPL] = {98401,526488,765349,34645,127615}; /* unique ID */
  25. float gross[NUM_EMPL]; /* gross pay */
  26. float hours[NUM_EMPL]; /* hours worked in a given week */
  27. int i; /* loop and array index */
  28. float overtime[NUM_EMPL]; /* overtime hours */
  29. float wageRate[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; /* hourly wage rate */
  30.  
  31. float emp_count; /* number of employees to process */
  32. float overtime_pay;
  33. float standard_pay;
  34.  
  35. for (i = 0; i < NUM_EMPL; ++i)
  36. {
  37. printf ("\nEnter number of hours worked: ");
  38.  
  39. /* get hours for employee */
  40. hours[i] = getHours (clockNumber[i]);
  41.  
  42. /* based on hours, figure out overtime and gross */
  43. if (hours [i] > STD_HOURS)
  44. {
  45.  
  46. standard_pay = STD_HOURS * wageRate [i];
  47.  
  48. overtime [i] = hours [i] - STD_HOURS;
  49.  
  50. overtime_pay = overtime [i] * (wageRate [i] * OT_RATE);
  51. }
  52. else /* no OT */
  53. {
  54.  
  55. standard_pay = wageRate [i] * hours [i];
  56.  
  57. overtime_pay = 0;
  58.  
  59. overtime [i] = 0;
  60. }
  61.  
  62. gross [i] = standard_pay + overtime_pay; /*the formula for gross is here, why isn't program picking up gross*/
  63.  
  64. printf ("\n\n----------------------------------------------------------");
  65.  
  66. printf ("\nClock # Wage Hours overtimeHours Gross");
  67.  
  68. printf ("\n----------------------------------------------------------");
  69.  
  70.  
  71. printf ("\n%06i %5.2f %5.1f %5.1f %7.2f\n",
  72. clockNumber [i], wageRate [i], hours [i], overtime [i], gross[i]);
  73. } /* for */
  74.  
  75. /* Print all the employees - call by reference */
  76. printData (clockNumber, wageRate, hours,
  77. overtime, gross, NUM_EMPL);
  78.  
  79. return (0);
  80.  
  81. }
  82.  
  83.  
  84. /*what is this extra half of the program what purpose does this serve?*/
  85.  
  86.  
  87. float getHours (long int clockNumber)
  88. {
  89.  
  90. float hoursWorked; /* hours worked in a given week */
  91.  
  92. /* Get Hours for each employee */
  93. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  94. scanf ("%f", &hoursWorked);
  95.  
  96. return (hoursWorked);
  97. }
  98.  
  99.  
  100.  
  101. void printData (long int clockNumber[], float wageRate[], float hours[],
  102. float overtime[], float gross[], int size)
  103. {
  104.  
  105. for (int i = 0; i < size; ++i)
  106. {
  107.  
  108. printf ("\n%06i %5.2f %5.1f %5.1f %7.2f\n",
  109. clockNumber [i], wageRate [i], hours [i], overtime [i], gross[i]);
  110. }
  111.  
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
Success #stdin #stdout 0s 4396KB
stdin
51.0

42.5

37.0

45.0

0.0
stdout
Enter number of hours worked: 
Enter hours worked by emp # 098401: 

----------------------------------------------------------
Clock # Wage Hours overtimeHours Gross
----------------------------------------------------------
098401 10.60  51.0  11.0  598.90

Enter number of hours worked: 
Enter hours worked by emp # 526488: 

----------------------------------------------------------
Clock # Wage Hours overtimeHours Gross
----------------------------------------------------------
526488  9.75  42.5   2.5  426.56

Enter number of hours worked: 
Enter hours worked by emp # 765349: 

----------------------------------------------------------
Clock # Wage Hours overtimeHours Gross
----------------------------------------------------------
765349 10.50  37.0   0.0  388.50

Enter number of hours worked: 
Enter hours worked by emp # 034645: 

----------------------------------------------------------
Clock # Wage Hours overtimeHours Gross
----------------------------------------------------------
034645 12.25  45.0   5.0  581.88

Enter number of hours worked: 
Enter hours worked by emp # 127615: 

----------------------------------------------------------
Clock # Wage Hours overtimeHours Gross
----------------------------------------------------------
127615  8.35   0.0   0.0    0.00

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