fork download
  1. #include <stdio.h>
  2.  
  3. // declared constants
  4. #define STD_HOURS 40.0
  5. #define NUM_EMPLOYEES 5
  6. #define OT_RATE 1.5
  7.  
  8. int main()
  9. {
  10. int clockNumber;
  11. float grossPay;
  12. float hours;
  13. float normalPay;
  14. float overtimeHrs;
  15. float overtimePay;
  16. float wageRate;
  17.  
  18. printf ("\n*** Pay Calculator ***");
  19.  
  20. // Process each employee
  21. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  22.  
  23. printf("\n\nEnter clock number: ");
  24. scanf("%d", &clockNumber);
  25.  
  26. printf("Enter wage rate: ");
  27. scanf("%f", &wageRate);
  28.  
  29. printf("Enter number of hours worked: ");
  30. scanf("%f", &hours);
  31.  
  32. // Initialize values
  33. overtimeHrs = 0.0;
  34. overtimePay = 0.0;
  35. normalPay = 0.0;
  36.  
  37. // Calculate pay
  38. if (hours > STD_HOURS) {
  39. overtimeHrs = hours - STD_HOURS;
  40. normalPay = wageRate * STD_HOURS;
  41. overtimePay = (OT_RATE * wageRate) * overtimeHrs;
  42. } else {
  43. normalPay = wageRate * hours;
  44. }
  45.  
  46. grossPay = normalPay + overtimePay;
  47.  
  48. // Output
  49. printf("\nClock# Wage Hours OT Gross\n");
  50. printf("-----------------------------------------\n");
  51. printf("%06d %6.2f %6.1f %6.1f %8.2f\n",
  52. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  53. }
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5308KB
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
*** Pay Calculator ***

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours   OT    Gross
-----------------------------------------
098401  10.60   51.0   11.0   598.90


Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours   OT    Gross
-----------------------------------------
526488   9.75   42.5    2.5   426.56


Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours   OT    Gross
-----------------------------------------
765349  10.50   37.0    0.0   388.50


Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours   OT    Gross
-----------------------------------------
034645  12.25   45.0    5.0   581.88


Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours   OT    Gross
-----------------------------------------
127615   8.35    0.0    0.0     0.00