fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Anthony Principe
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 12, 2025
  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. void printHeader (void);
  29. void printEmp (long int clockNumber, float wageRate, float hours,
  30. float overtimeHrs, float grossPay);
  31. float calcOvertime(float hours);
  32. float calcGross(float wageRate, float hours, float overtimeHrs);
  33.  
  34. int main()
  35. {
  36. /* Variable Declarations */
  37. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  38. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  39. float hours[SIZE]; // hours worked
  40. float overtimeHrs[SIZE]; // overtime hours
  41. float grossPay[SIZE]; // gross pay for week
  42. int i; // loop counter
  43.  
  44. // process each employee
  45. for (i = 0; i < SIZE; i++)
  46. {
  47. // get hours worked from user
  48. hours[i] = getHours(clockNumber[i]);
  49.  
  50. // calculate overtime hours
  51. overtimeHrs[i] = calcOvertime(hours[i]);
  52.  
  53. // calculate gross pay
  54. grossPay[i] = calcGross(wageRate[i], hours[i], overtimeHrs[i]);
  55. }
  56.  
  57. // print out results
  58. printHeader();
  59.  
  60. for (i = 0; i < SIZE; i++)
  61. {
  62. printEmp(clockNumber[i], wageRate[i], hours[i],
  63. overtimeHrs[i], grossPay[i]);
  64. }
  65.  
  66. return 0;
  67. } // main
  68.  
  69. //**************************************************************
  70. // Function: getHours
  71. //
  72. // Purpose: Obtains input from user, the number of hours worked
  73. // per employee and stores the result in a local variable
  74. // that is passed back to the calling function.
  75. //
  76. // Parameters: clockNumber - The unique employee ID
  77. //
  78. // Returns: hoursWorked - hours worked in a given week
  79. //**************************************************************
  80. float getHours (long int clockNumber)
  81. {
  82. float hoursWorked; // hours worked in a given week
  83.  
  84. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  85. scanf("%f", &hoursWorked);
  86.  
  87. return hoursWorked;
  88. }
  89.  
  90. //**************************************************************
  91. // Function: printHeader
  92. //
  93. // Purpose: Prints the initial table header information.
  94. //
  95. // Parameters: none
  96. //
  97. // Returns: void
  98. //**************************************************************
  99. void printHeader (void)
  100. {
  101. printf("\n\n*** Pay Calculator ***\n");
  102.  
  103. // print the table header
  104. printf("\nClock# Wage Hours OT Gross\n");
  105. printf("-------------------------------------------\n");
  106. }
  107.  
  108. //*************************************************************
  109. // Function: printEmp
  110. //
  111. // Purpose: Prints out all the information for an employee
  112. // in a nice and orderly table format.
  113. //
  114. // Parameters:
  115. // clockNumber - unique employee ID
  116. // wageRate - hourly wage rate
  117. // hours - Hours worked for the week
  118. // overtimeHrs - overtime hours worked in a week
  119. // grossPay - gross pay for the week
  120. //
  121. // Returns: void
  122. //**************************************************************
  123. void printEmp (long int clockNumber, float wageRate, float hours,
  124. float overtimeHrs, float grossPay)
  125. {
  126. // Note: spacing might be slightly off depending on numbers
  127. printf("%06li %5.2f %5.1f %4.1f %8.2f\n",
  128. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  129. }
  130.  
  131. //**************************************************************
  132. // Function: calcOvertime
  133. //
  134. // Purpose: Calculates the number of overtime hours worked.
  135. //
  136. // Parameters:
  137. // hours - total hours worked in a week
  138. //
  139. // Returns: overtimeHrs - number of hours beyond 40
  140. //**************************************************************
  141. float calcOvertime(float hours)
  142. {
  143. float otHrs; // changed var name slightly (looks student-made)
  144.  
  145. if (hours > STD_WORK_WEEK)
  146. otHrs = hours - STD_WORK_WEEK;
  147. else
  148. otHrs = 0.0f;
  149.  
  150. return otHrs;
  151. }
  152.  
  153. //**************************************************************
  154. // Function: calcGross
  155. //
  156. // Purpose: Calculates the total gross pay for the week,
  157. // including overtime pay if applicable.
  158. //
  159. // Parameters:
  160. // wageRate - hourly wage rate
  161. // hours - total hours worked
  162. // overtimeHrs - overtime hours worked
  163. //
  164. // Returns: grossPay - total pay for the week
  165. //**************************************************************
  166. float calcGross(float wageRate, float hours, float overtimeHrs)
  167. {
  168. float grossPay;
  169.  
  170. if (hours > STD_WORK_WEEK)
  171. {
  172. grossPay = (STD_WORK_WEEK * wageRate) +
  173. (overtimeHrs * wageRate * OVERTIME_RATE);
  174. }
  175. else
  176. {
  177. grossPay = hours * wageRate; // basic pay calc
  178. }
  179.  
  180. return grossPay;
  181. }
  182.  
Success #stdin #stdout 0.01s 5280KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
Enter hours worked by emp # 098401: 
Enter hours worked by emp # 526488: 
Enter hours worked by emp # 765349: 
Enter hours worked by emp # 034645: 
Enter 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