fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - structure
  4. //
  5. // Name: Jesus Castillo
  6. //
  7. // Class: C Programming, Summer, 2025
  8. //
  9. // Date: 7/06/2025
  10. //
  11. // Description: Write a C program that will calculate
  12. // thegross pay of a set of employees. Continue
  13. // to use all the features from your past assignments.
  14. // In particular, expand upon your previous assignment
  15. // and continue to use multiple functions and constants
  16. // to help with various tasks called upon by your program.
  17. //
  18. // All functions are called by value
  19. //
  20. //********************************************************
  21.  
  22. #include <stdio.h>
  23.  
  24. // constants
  25. #define SIZE 5
  26. #define OVERTIME_RATE 1.5f
  27. #define STD_WORK_WEEK 40.0f
  28. #define OT_RATE 1.5
  29. #define STD_HOURS 40.0
  30.  
  31. struct employee {
  32. long int clockNumber;
  33. float wageRate;
  34. float hours;
  35. float overtimeHrs;
  36. float grossPay;
  37.  
  38. };
  39.  
  40. int main() {
  41.  
  42. struct employee employeeData[SIZE] = {
  43. {98401, 10.60, 51, 0, 0},
  44. {526488, 9.75, 42.5, 0, 0},
  45. {765349, 10.50, 37.0, 0, 0},
  46. {34645, 12.25, 45.0, 0, 0},
  47. {127615, 8.35, 0, 0, 0}
  48. };
  49.  
  50. for (int i = 0; i < SIZE; ++i) {
  51.  
  52. printf("Enter hours worked by employee %06ld: ", employeeData[i].clockNumber);
  53. scanf("%f", &employeeData[i].hours);
  54. if (employeeData[i].hours > STD_HOURS) {
  55. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  56. } else {
  57. employeeData[i].overtimeHrs = 0.0f;
  58. }
  59. float regularHours = (employeeData[i].hours > STD_HOURS) ? STD_HOURS : employeeData[i].hours;
  60. employeeData[i].grossPay = (regularHours * employeeData[i].wageRate) + (employeeData[i].overtimeHrs * employeeData[i].wageRate * OT_RATE);
  61.  
  62.  
  63. }
  64.  
  65. printf("\nClock# Wage Hours OT Gross\n");
  66. printf("----------------------------------------\n");
  67. for (int i = 0; i < SIZE; ++i) {
  68. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  69. employeeData[i].clockNumber,
  70. employeeData[i].wageRate,
  71. employeeData[i].hours,
  72. employeeData[i].overtimeHrs,
  73. employeeData[i].grossPay);
  74.  
  75.  
  76. }
  77.  
  78. return 0;
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Enter hours worked by employee 098401: Enter hours worked by employee 526488: Enter hours worked by employee 765349: Enter hours worked by employee 034645: Enter hours worked by employee 127615: 
Clock#   Wage   Hours   OT     Gross
----------------------------------------
098401  10.60   51.0   11.0    598.90
526488   9.75   42.5    2.5    426.56
765349  10.50   37.0    0.0    388.50
034645  12.25   45.0    5.0    581.88
127615   8.35    0.0    0.0      0.00