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. // unique employee identifier
  11. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  12.  
  13. float grossPay[SIZE];
  14. float hours[SIZE];
  15. int i;
  16. float normalPay[SIZE];
  17. float overtimeHrs[SIZE];
  18. float overtimePay[SIZE];
  19.  
  20. // hourly pay for each employee
  21. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  22.  
  23. printf("\n*** Pay Calculator ***\n\n");
  24.  
  25. // Process each employee one at a time
  26. for (i = 0; i < SIZE; i++)
  27. {
  28. // Prompt and read hours worked
  29. scanf("%f", &hours[i]);
  30.  
  31. if (hours[i] >= STD_HOURS)
  32. {
  33. overtimeHrs[i] = hours[i] - STD_HOURS;
  34.  
  35. normalPay[i] = STD_HOURS * wageRate[i];
  36. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  37. } // End if
  38. else // no overtime
  39. {
  40. overtimeHrs[i] = 0;
  41.  
  42. normalPay[i] = hours[i] * wageRate[i];
  43. overtimePay[i] = 0;
  44. } // End else
  45.  
  46. // Calculate Gross Pay
  47. grossPay[i] = normalPay[i] + overtimePay[i];
  48. }
  49.  
  50. // Print table header
  51. printf("\n%-10s %-10s %-10s %-12s %-12s %-12s\n",
  52. "Clock#", "Wage", "Hours", "Normal Pay", "OT", "Gross");
  53.  
  54. printf("---------------------------------------------------------------------\n");
  55.  
  56. // Print employee information
  57. for (i = 0; i < SIZE; i++)
  58. {
  59. printf("%-10ld %-10.2f %-10.2f %-12.2f %-12.2f %-12.2f\n",
  60. clockNumber[i],
  61. wageRate[i],
  62. hours[i],
  63. normalPay[i],
  64. overtimePay[i],
  65. grossPay[i]);
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


Clock#     Wage       Hours      Normal Pay   OT           Gross       
---------------------------------------------------------------------
98401      10.60      51.00      424.00       174.90       598.90      
526488     9.75       42.50      390.00       36.56        426.56      
765349     10.50      37.00      388.50       0.00         388.50      
34645      12.25      45.00      490.00       91.88        581.88      
127615     8.35       0.00       0.00         0.00         0.00