fork download
  1. #include <stdio.h>
  2.  
  3. // constants to use
  4. #define SIZE 5
  5. #define STD_HOURS 40.0
  6. #define OT_RATE 1.5
  7.  
  8. int main()
  9. {
  10. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  11.  
  12. float grossPay[SIZE];
  13. float hours[SIZE];
  14. int i;
  15. float normalPay[SIZE];
  16. float overtimeHrs[SIZE];
  17. float overtimePay[SIZE];
  18.  
  19. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  20.  
  21. float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
  22.  
  23. printf("\n*** Pay Calculator ***\n\n");
  24.  
  25. for (i = 0; i < SIZE; i++)
  26. {
  27. printf("Enter hours for %06ld: ", clockNumber[i]);
  28. scanf("%f", &hours[i]);
  29.  
  30. if (hours[i] >= STD_HOURS)
  31. {
  32. overtimeHrs[i] = hours[i] - STD_HOURS;
  33. normalPay[i] = STD_HOURS * wageRate[i];
  34. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  35. }
  36. else
  37. {
  38. overtimeHrs[i] = 0;
  39. normalPay[i] = hours[i] * wageRate[i];
  40. overtimePay[i] = 0;
  41. }
  42.  
  43. grossPay[i] = normalPay[i] + overtimePay[i];
  44.  
  45. totalWage += wageRate[i];
  46. totalHours += hours[i];
  47. totalOT += overtimeHrs[i];
  48. totalGross += grossPay[i];
  49. }
  50.  
  51. // Table header
  52. printf("\n%-8s %12s %10s %10s %14s\n",
  53. "Clock#", "Wage", "Hours", "OT", "Gross");
  54. printf("---------------------------------------------------------------------\n");
  55.  
  56. for (i = 0; i < SIZE; i++)
  57. {
  58. printf("%-8ld $%10.2f %10.2f %10.2f $%12.2f\n",
  59. clockNumber[i],
  60. wageRate[i],
  61. hours[i],
  62. overtimeHrs[i],
  63. grossPay[i]);
  64. }
  65.  
  66. printf("---------------------------------------------------------------------\n");
  67.  
  68. printf("%-8s $%10.2f %10.2f %10.2f $%12.2f\n",
  69. "Total",
  70. totalWage, totalHours, totalOT, totalGross);
  71.  
  72. printf("%-8s $%10.2f %10.2f %10.2f $%12.2f\n",
  73. "Average",
  74. totalWage / SIZE,
  75. totalHours / SIZE,
  76. totalOT / SIZE,
  77. totalGross / SIZE);
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours for 098401: Enter hours for 526488: Enter hours for 765349: Enter hours for 034645: Enter hours for 127615: 
Clock#           Wage      Hours         OT          Gross
---------------------------------------------------------------------
98401    $     10.60      51.00      11.00 $      598.90
526488   $      9.75      42.50       2.50 $      426.56
765349   $     10.50      37.00       0.00 $      388.50
34645    $     12.25      45.00       5.00 $      581.88
127615   $      8.35       0.00       0.00 $        0.00
---------------------------------------------------------------------
Total    $     51.45     175.50      18.50 $     1995.84
Average  $     10.29      35.10       3.70 $      399.17