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