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. // TODO: Declare and use at least one more constant
  9.  
  10. int main()
  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; // Overtime hours worked beyond a normal week (40 hours)
  17. float overtimePay; // Any hours worked past the normal scheduled work week
  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 initialization statements if desired
  38. // initialize so initial template prints these both as zero
  39. //grossPay = 0;
  40. //overtimeHours = 0;
  41.  
  42. // Calculate the overtime hours, normal pay, and overtime pay
  43. if (hours > STD_HOURS) {
  44. overtimeHrs = hours - STD_HOURS;
  45. }
  46. else {
  47. overtimeHrs = 0.0;
  48. }
  49.  
  50. // Calculate the gross pay with normal pay and any additional overtime pay
  51. if (overtimeHrs > 0) {
  52. grossPay = (STD_HOURS * wageRate) + (overtimeHrs * wageRate * OVERTIME_RATE);
  53. }
  54. else {
  55. grossPay = hours * wageRate;
  56. }
  57. // Print out information on the current employee
  58. // Optional TODO: Feel free to also print out normalPay and overtimePay
  59. printf("\n\nClock# Wage Hours OT Gross\n");
  60. printf("------------------------------------------------\n");
  61. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  62. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  63. }
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0.01s 5280KB
stdin
98401
10.60
51.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
------------------------------------------------
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
------------------------------------------------
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
------------------------------------------------
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
------------------------------------------------
098401 10.60  51.0  11.0   598.90