fork download
  1. #include <stdio.h>
  2.  
  3. #define NUM_EMPL 5 /* number of employees to process */
  4. #define OVERTIME_RATE 1.5f /* Overtime pay rate is 1.5 times regular wage */
  5. #define STD_WORK_WEEK 40.f /* 40 hours equals standard work week for pay calculation; beyond that is Overtime Pay */
  6.  
  7. /* Global structure below for the employee with members of Employee ID, Hourly Wage, Hours Worked, */
  8. /* Overtime Hours Worked, and Gross Pay Earned */
  9.  
  10. struct employee
  11. {
  12. int id_number;
  13. float wage;
  14. float hours;
  15. float overtime;
  16. float gross;
  17. };
  18.  
  19. /* Function Prototypes */
  20.  
  21. struct employee* readEmployee (struct employee emp[NUM_EMPL]);
  22. void Output_Results_Screen (struct employee emp [NUM_EMPL]);
  23.  
  24. /* add functions here */
  25. /* each function needs the description box */
  26. struct employee* readEmployee(struct employee emp[NUM_EMPL])
  27. {
  28. int i = 0;
  29. for (i = 0; i < NUM_EMPL; i++) {
  30. printf("\nEnter the number of hours of employee %d: ", emp[i].id_number);
  31. scanf("%f", &emp[i].hours);
  32. if (emp[i].hours > STD_WORK_WEEK) {
  33. emp[i].overtime = emp[i].hours - STD_WORK_WEEK;
  34. emp[i].gross = (STD_WORK_WEEK * emp[i].wage + emp[i].overtime * emp[i].wage * OVERTIME_RATE);
  35. } else {
  36. emp[i].overtime = 0;
  37. emp[i].gross = (emp[i].hours * emp[i].wage);
  38. }
  39. }
  40. return emp;
  41. }
  42.  
  43. void Output_Results_Screen (struct employee emp [NUM_EMPL] )
  44. {
  45. int i;
  46.  
  47. printf ("\n\t----------------------------------------------------------\n");
  48. printf ("\tClock # Wage Hours OT Gross\n");
  49. printf ("\t----------------------------------------------------------\n");
  50.  
  51. for (i = 0; i < NUM_EMPL; i++) {
  52. printf("\t%06i %5.2f %5.1f %5.1f %7.2f\n", emp[i].id_number, emp[i].wage, emp[i].hours, emp[i].overtime,
  53. emp[i].gross);
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. /* Set up a local variable to store the employee information */
  60. struct employee emps[NUM_EMPL] = {
  61. { 98401, 10.60 },
  62. { 526488, 9.75 },
  63. { 765349, 10.50 },
  64. { 34645, 12.25 },
  65. { 127615, 8.35}
  66. };
  67. readEmployee(emps);
  68. Output_Results_Screen (emps);
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Enter the number of hours of employee 98401: 
Enter the number of hours of employee 526488: 
Enter the number of hours of employee 765349: 
Enter the number of hours of employee 34645: 
Enter the number of hours of employee 127615: 
	----------------------------------------------------------
	Clock # Wage Hours OT Gross
	----------------------------------------------------------
	098401 10.60   0.0   0.0    0.00
	526488  9.75   0.0   0.0    0.00
	765349 10.50   0.0   0.0    0.00
	034645 12.25   0.0   0.0    0.00
	127615  8.35   0.0   0.0    0.00