fork download
  1. #include <stdio.h>
  2.  
  3. // Declare constants
  4. #define STD_HOURS 40.0
  5. #define NUM_EMPLOYEES 5
  6. #define OVERTIME_RATE 1.5
  7.  
  8. int main()
  9. {
  10.  
  11. int clockNumber; // Employee clock number
  12. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  13. float hours; // Total hours worked in a week
  14. float normalPay; // Standard weekly normal pay without overtime
  15. float overtimeHrs; // Any hours worked past the normal scheduled work week
  16. float overtimePay; // Additional overtime pay for any overtime hours worked
  17. float wageRate; // Hourly wage for an employee
  18.  
  19. printf("\n*** Pay Calculator ***");
  20.  
  21. // Process each employee
  22. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  23.  
  24. // Prompt the user for the clock number
  25. printf("\n\nEnter clock number: ");
  26. scanf("%d", &clockNumber);
  27.  
  28. // Prompt the user for the wage rate
  29. printf("\nEnter wage rate: ");
  30. scanf("%f", &wageRate);
  31.  
  32. // Prompt the user for the number of hours worked
  33. printf("\nEnter number of hours worked: ");
  34. scanf("%f", &hours);
  35.  
  36. // Optional TODO: Remove these two statements if desired
  37. // ... were added just for the template to print some values out of the box
  38. grossPay = 0;
  39. overtimeHrs = 0;
  40.  
  41. // Calculate the overtime hours, normal pay, and overtime pay
  42. if (hours > STD_HOURS) {
  43. overtimeHrs = hours - STD_HOURS;
  44. normalPay = STD_HOURS * wageRate;
  45. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  46. } else {
  47. overtimeHrs = 0;
  48. normalPay = hours * wageRate;
  49. overtimePay = 0;
  50. }
  51.  
  52. // Calculate the gross pay with normal pay and any additional overtime pay
  53. grossPay = normalPay + overtimePay;
  54.  
  55. // Print out information on the current employee
  56. // Optional TODO: Feel free to also print out normalPay and overtimePay
  57. printf("\n\nClock# Wage Hours OT Gross\n");
  58. printf("----------------------------------------------\n");
  59. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  60. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  61. }
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 5312KB
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