fork download
  1. #include <stdio.h>
  2.  
  3. #define SIZE 5
  4. #define STD_HOURS 40.0
  5. #define OT_RATE 1.5
  6.  
  7. int main(void)
  8. {
  9. int clock[SIZE];
  10. double wage[SIZE];
  11. double hours[SIZE];
  12. double overtimeHours[SIZE];
  13. double grossPay[SIZE];
  14.  
  15. double normalPay;
  16. double overtimePay;
  17.  
  18. int i;
  19.  
  20. /* Input employee information */
  21. for (i = 0; i < SIZE; ++i)
  22. {
  23. printf("Enter Clock#, Wage, and Hours for employee %d: ", i + 1);
  24. scanf("%d %lf %lf", &clock[i], &wage[i], &hours[i]);
  25.  
  26. /* Calculate overtime hours */
  27. if (hours[i] > STD_HOURS)
  28. overtimeHours[i] = hours[i] - STD_HOURS;
  29. else
  30. overtimeHours[i] = 0.0;
  31.  
  32. /* Calculate normal pay */
  33. if (hours[i] > STD_HOURS)
  34. normalPay = STD_HOURS * wage[i];
  35. else
  36. normalPay = hours[i] * wage[i];
  37.  
  38. /* Calculate overtime pay */
  39. overtimePay = overtimeHours[i] * wage[i] * OT_RATE;
  40.  
  41. /* Calculate gross pay */
  42. grossPay[i] = normalPay + overtimePay;
  43. }
  44.  
  45. /* Print results */
  46. printf("\n");
  47. printf("------------------------------------------------\n");
  48. printf("Clock# Wage Hours OT Gross\n");
  49. printf("------------------------------------------------\n");
  50.  
  51. for (i = 0; i < SIZE; ++i)
  52. {
  53. printf("%06d %6.2f %6.1f %6.1f %8.2f\n",
  54. clock[i],
  55. wage[i],
  56. hours[i],
  57. overtimeHours[i],
  58. grossPay[i]);
  59. }
  60.  
  61. printf("------------------------------------------------\n");
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 5320KB
stdin
98401 10.60 51.0
526488 9.75 42.5
765349 10.50 37.0
34645 12.25 45.0
127615 8.35 0.0
stdout
Enter Clock#, Wage, and Hours for employee 1: Enter Clock#, Wage, and Hours for employee 2: Enter Clock#, Wage, and Hours for employee 3: Enter Clock#, Wage, and Hours for employee 4: Enter Clock#, Wage, and Hours for employee 5: 
------------------------------------------------
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
------------------------------------------------