fork download
  1. #include <stdio.h>
  2.  
  3. // constants to use
  4. #define SIZE 5 // number of employees to process
  5. #define STD_HOURS 40.0 // normal work week hours before overtime
  6. #define OT_RATE 1.5 // time and half overtime setting
  7.  
  8. int main()
  9. {
  10. // ------------------------------------------------------------
  11. // Variable Declarations
  12. // ------------------------------------------------------------
  13.  
  14. // unique employee identifier
  15. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  16.  
  17. // hourly pay for each employee
  18. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  19.  
  20. float hours[SIZE]; // hours worked in a given week
  21. float overtimeHrs[SIZE]; // overtime hours worked
  22. float normalPay[SIZE]; // normal weekly pay
  23. float overtimePay[SIZE]; // overtime pay
  24. float grossPay[SIZE]; // total weekly pay
  25. int i; // loop index
  26.  
  27. printf("\n*** Pay Calculator ***\n\n");
  28.  
  29. // ------------------------------------------------------------
  30. // Input Loop — Prompt and Read Hours Worked
  31. // ------------------------------------------------------------
  32. for (i = 0; i < SIZE; i++)
  33. {
  34. // Prompt and read hours for each employee
  35. printf("\nEnter the number of hours worked for employee %ld: ",
  36. clockNumber[i]);
  37. scanf("%f", &hours[i]);
  38.  
  39. // --------------------------------------------------------
  40. // Calculate overtime and pay
  41. // --------------------------------------------------------
  42. if (hours[i] >= STD_HOURS)
  43. {
  44. // Employee worked overtime
  45. overtimeHrs[i] = hours[i] - STD_HOURS;
  46.  
  47. // Normal pay is capped at STD_HOURS
  48. normalPay[i] = STD_HOURS * wageRate[i];
  49.  
  50. // Overtime pay uses OT_RATE multiplier
  51. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  52. }
  53. else
  54. {
  55. // No overtime
  56. overtimeHrs[i] = 0.0;
  57.  
  58. // All hours are normal hours
  59. normalPay[i] = hours[i] * wageRate[i];
  60.  
  61. // No overtime pay
  62. overtimePay[i] = 0.0;
  63. }
  64.  
  65. // Total gross pay
  66. grossPay[i] = normalPay[i] + overtimePay[i];
  67. }
  68.  
  69. // ------------------------------------------------------------
  70. // Output Table Header
  71. // ------------------------------------------------------------
  72. printf("\nClock# Wage Hours OT Normal OT Pay Gross\n");
  73. printf("-----------------------------------------------------------\n");
  74.  
  75. // ------------------------------------------------------------
  76. // Output Loop — Print Employee Payroll Data
  77. // ------------------------------------------------------------
  78. for (i = 0; i < SIZE; i++)
  79. {
  80. printf("%06ld %5.2f %5.1f %4.1f %7.2f %7.2f %7.2f\n",
  81. clockNumber[i],
  82. wageRate[i],
  83. hours[i],
  84. overtimeHrs[i],
  85. normalPay[i],
  86. overtimePay[i],
  87. grossPay[i]);
  88. }
  89.  
  90. return 0;
  91. }
Success #stdin #stdout 0s 5308KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


Enter the number of hours worked for employee 98401: 
Enter the number of hours worked for employee 526488: 
Enter the number of hours worked for employee 765349: 
Enter the number of hours worked for employee 34645: 
Enter the number of hours worked for employee 127615: 
Clock#     Wage   Hours   OT   Normal   OT Pay   Gross
-----------------------------------------------------------
098401   10.60   51.0  11.0   424.00   174.90   598.90
526488    9.75   42.5   2.5   390.00    36.56   426.56
765349   10.50   37.0   0.0   388.50     0.00   388.50
034645   12.25   45.0   5.0   490.00    91.88   581.88
127615    8.35    0.0   0.0     0.00     0.00     0.00