fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Seth Hin
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: February 28, 2026
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // All functions are called by value
  16. //
  17. //********************************************************
  18.  
  19. #include <stdio.h>
  20.  
  21. // constants
  22. #define SIZE 5
  23. #define OVERTIME_RATE 1.5f
  24. #define STD_WORK_WEEK 40.0f
  25.  
  26. // function prototypes
  27. float getHours (long int clockNumber);
  28. float calcOvertime (float hours);
  29. float calcGross (float hours, float wageRate, float overtimeHrs);
  30. void printHeader (void);
  31. void printEmp (long int clockNumber, float wageRate, float hours,
  32. float overtimeHrs, float grossPay);
  33. void printTotals(float totalWage, float totalHours,
  34. float totalOT, float totalGross);
  35.  
  36. int main()
  37. {
  38. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615};
  39. float grossPay[SIZE];
  40. float hours[SIZE];
  41. float overtimeHrs[SIZE];
  42. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35};
  43.  
  44. float totalWage = 0.0f;
  45. float totalHours = 0.0f;
  46. float totalOT = 0.0f;
  47. float totalGross = 0.0f;
  48.  
  49. int i;
  50.  
  51. for (i = 0; i < SIZE; ++i)
  52. {
  53. hours[i] = getHours(clockNumber[i]);
  54. overtimeHrs[i] = calcOvertime(hours[i]);
  55. grossPay[i] = calcGross(hours[i], wageRate[i], overtimeHrs[i]);
  56.  
  57. totalWage += wageRate[i];
  58. totalHours += hours[i];
  59. totalOT += overtimeHrs[i];
  60. totalGross += grossPay[i];
  61. }
  62.  
  63. printHeader();
  64.  
  65. for (i = 0; i < SIZE; ++i)
  66. {
  67. printEmp(clockNumber[i], wageRate[i], hours[i],
  68. overtimeHrs[i], grossPay[i]);
  69. }
  70.  
  71. printTotals(totalWage, totalHours, totalOT, totalGross);
  72.  
  73. return 0;
  74. }
  75.  
  76.  
  77. // Function: getHours
  78. float getHours (long int clockNumber)
  79. {
  80. float hoursWorked;
  81.  
  82. printf("\n Hours worked by emp # %06li: ", clockNumber);
  83. scanf ("%f", &hoursWorked);
  84.  
  85. return hoursWorked;
  86. }
  87.  
  88.  
  89. // Function: calcOvertime
  90. float calcOvertime (float hours)
  91. {
  92. float overtime;
  93.  
  94. if (hours > STD_WORK_WEEK)
  95. overtime = hours - STD_WORK_WEEK;
  96. else
  97. overtime = 0.0f;
  98.  
  99. return overtime;
  100. }
  101.  
  102.  
  103. // Function: calcGross
  104. float calcGross (float hours, float wageRate, float overtimeHrs)
  105. {
  106. float regularPay;
  107. float overtimePay;
  108. float gross;
  109.  
  110. regularPay = (hours - overtimeHrs) * wageRate;
  111. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  112. gross = regularPay + overtimePay;
  113.  
  114. return gross;
  115. }
  116.  
  117. // Function: printHeader
  118. void printHeader (void)
  119. {
  120. printf("\n\n*** Pay Calculator ***\n");
  121. printf("\n----------------------------------------------------------\n");
  122. printf("Clock# Wage Hours OT Gross\n");
  123. printf("----------------------------------------------------------\n");
  124. }
  125.  
  126. // Function: printEmp
  127. void printEmp (long int clockNumber, float wageRate, float hours,
  128. float overtimeHrs, float grossPay)
  129. {
  130. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  131. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  132. }
  133.  
  134. // Function: printTotals
  135. void printTotals(float totalWage, float totalHours,
  136. float totalOT, float totalGross)
  137. {
  138. printf("----------------------------------------------------------\n");
  139.  
  140. printf("Total %5.2f %5.1f %5.1f %8.2f\n",
  141. totalWage, totalHours, totalOT, totalGross);
  142.  
  143. printf("Average %5.2f %5.1f %5.1f %8.2f\n",
  144. totalWage / SIZE,
  145. totalHours / SIZE,
  146. totalOT / SIZE,
  147. totalGross / SIZE);
  148. }
Success #stdin #stdout 0.01s 5324KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
 Hours worked by emp # 098401: 
 Hours worked by emp # 526488: 
 Hours worked by emp # 765349: 
 Hours worked by emp # 034645: 
 Hours worked by emp # 127615: 

*** Pay Calculator ***

----------------------------------------------------------
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
----------------------------------------------------------
Total    51.45   175.5    18.5    1995.84
Average  10.29    35.1     3.7     399.17