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. #include <stdio.h>
  22.  
  23. // constants
  24. #define SIZE 5
  25. #define OVERTIME_RATE 1.5f
  26. #define STD_WORK_WEEK 40.0f
  27. #define OT_RATE 1.5
  28. #define STD_HOURS 40.0
  29.  
  30. struct employee {
  31. long int clockNumber;
  32. float wageRate;
  33. float hours;
  34. float overtimeHrs;
  35. float grossPay;
  36.  
  37. };
  38.  
  39. int main() {
  40.  
  41. struct employee employeeData[SIZE] = {
  42. {98401, 10.60, 51, 0, 0},
  43. {526488, 9.75, 42.5, 0, 0},
  44. {765349, 10.50, 37.0, 0, 0},
  45. {34645, 12.25, 45.0, 0, 0},
  46. {127615, 8.35, 0, 0, 0}
  47. };
  48.  
  49. for (int i = 0; i < SIZE; ++i) {
  50. printf("\n");
  51. printf("Enter hours worked by employee %06ld: " , employeeData[i].clockNumber);
  52.  
  53. printf("%f", employeeData[i].hours);
  54.  
  55. if (employeeData[i].hours > STD_HOURS) {
  56. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  57. } else {
  58. employeeData[i].overtimeHrs = 0.0f;
  59. }
  60.  
  61.  
  62. float regularHours = (employeeData[i].hours > STD_HOURS) ? STD_HOURS : employeeData[i].hours;
  63. employeeData[i].grossPay = (regularHours * employeeData[i].wageRate) + (employeeData[i].overtimeHrs * employeeData[i].wageRate * OT_RATE);
  64.  
  65.  
  66.  
  67. }
  68. printf("\n");
  69. printf("----------------------------------------\n");
  70. printf("\nClock# Wage Hours OT Gross\n");
  71. printf("----------------------------------------\n");
  72. for (int i = 0; i < SIZE; ++i) {
  73. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  74. employeeData[i].clockNumber,
  75. employeeData[i].wageRate,
  76. employeeData[i].hours,
  77. employeeData[i].overtimeHrs,
  78. employeeData[i].grossPay);
  79. }
  80.  
  81. return 0;
  82.  
  83. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Enter hours worked by employee 098401: 51.000000
Enter hours worked by employee 526488: 42.500000
Enter hours worked by employee 765349: 37.000000
Enter hours worked by employee 034645: 45.000000
Enter hours worked by employee 127615: 0.000000
----------------------------------------

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