fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Henri Biqiku
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: October 11, 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. void printHeader (void);
  29. void printEmp (long int clockNumber, float wageRate, float hours,
  30. float overtimeHrs, float grossPay);
  31.  
  32. // TODO: Add other function prototypes here as needed
  33. float calculateOvertime(float hours);
  34. float calculateGrossPay(float wageRate, float hours, float overtimeHrs);
  35. int main()
  36. {
  37.  
  38. /* Variable Declarations */
  39.  
  40. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  41. float grossPay[SIZE]; // gross pay
  42. float hours[SIZE]; // hours worked in a given week
  43. int i; // loop and array index
  44. float overtimeHrs[SIZE]; // overtime hours
  45. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  46.  
  47. // process each employee
  48. for (i = 0; i < SIZE; ++i)
  49. {
  50.  
  51. // Read in hours for employee
  52. hours[i] = getHours (clockNumber[i]);
  53.  
  54. // TODO: Function call to calculate overtime hours
  55. overtimeHrs[i] = calculateOvertime(hours[i]);
  56. // TODO: Function call to calculate gross pay
  57. grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
  58.  
  59. }
  60.  
  61. // print the header info
  62. printHeader();
  63.  
  64. // print out each employee
  65. for (i = 0; i < SIZE; ++i)
  66. {
  67.  
  68. // Print all the employees - call by value
  69. printEmp (clockNumber[i], wageRate[i], hours[i],
  70. overtimeHrs[i], grossPay[i]);
  71.  
  72. } // for
  73.  
  74. return (0);
  75.  
  76. } // main
  77.  
  78. //**************************************************************
  79. // Function: getHours
  80. //
  81. // Purpose: Obtains input from user, the number of hours worked
  82. // per employee and stores the result in a local variable
  83. // that is passed back to the calling function.
  84. //
  85. // Parameters: clockNumber - The unique employee ID
  86. //
  87. // Returns: hoursWorked - hours worked in a given week
  88. //
  89. //**************************************************************
  90.  
  91. float getHours (long int clockNumber)
  92. {
  93.  
  94. float hoursWorked; // hours worked in a given week
  95.  
  96. // Read in hours for employee
  97. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  98. scanf ("%f", &hoursWorked);
  99.  
  100. // return hours back to the calling function
  101. return (hoursWorked);
  102.  
  103. } // getHours
  104.  
  105. //**************************************************************
  106. // Function: printHeader
  107. //
  108. // Purpose: Prints the initial table header information.
  109. //
  110. // Parameters: none
  111. //
  112. // Returns: void
  113. //
  114. //**************************************************************
  115.  
  116. void printHeader (void)
  117. {
  118.  
  119. printf ("\n\n*** Pay Calculator ***\n");
  120.  
  121. // print the table header
  122. printf("\nClock# Wage Hours OT Gross\n");
  123. printf("------------------------------------------------\n");
  124.  
  125. } // printHeader
  126.  
  127. //*************************************************************
  128. // Function: printEmp
  129. //
  130. // Purpose: Prints out all the information for an employee
  131. // in a nice and orderly table format.
  132. //
  133. // Parameters:
  134. //
  135. // clockNumber - unique employee ID
  136. // wageRate - hourly wage rate
  137. // hours - Hours worked for the week
  138. // overtimeHrs - overtime hours worked in a week
  139. // grossPay - gross pay for the week
  140. //
  141. // Returns: void
  142. //
  143. //**************************************************************
  144.  
  145. void printEmp (long int clockNumber, float wageRate, float hours,
  146. float overtimeHrs, float grossPay)
  147. {
  148.  
  149. // print the employee
  150.  
  151. // TODO: add code to print out a single employee
  152. printf("%06li %5.2f %5.1f %4.1f %8.2f\n",
  153. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  154. }
  155.  
  156.  
  157. // TODO: Add other functions here as needed
  158. // ... remember your comment block headers for each function
  159. //**************************************************************
  160. // Function: calculateOvertime
  161. //
  162. // Purpose: Calculates the overtime hours worked.
  163. //
  164. // Parameters: hours - hours worked during the week
  165. //
  166. // Returns: overtimeHrs - overtime hours worked
  167. //**************************************************************
  168. float calculateOvertime(float hours)
  169. {
  170. float overtimeHrs;
  171.  
  172. if (hours > STD_WORK_WEEK)
  173. overtimeHrs = hours - STD_WORK_WEEK;
  174. else
  175. overtimeHrs = 0.0f;
  176.  
  177. return overtimeHrs;
  178. }
  179.  
  180. //**************************************************************
  181. // Function: calculateGrossPay
  182. //
  183. // Purpose: Calculates the gross pay for an employee.
  184. //
  185. // Parameters:
  186. // wageRate - hourly wage rate
  187. // hours - total hours worked
  188. // overtimeHrs - overtime hours worked
  189. //
  190. // Returns: grossPay - total gross pay
  191. //**************************************************************
  192. float calculateGrossPay(float wageRate, float hours, float overtimeHrs)
  193. {
  194. float normalPay;
  195. float overtimePay;
  196. float grossPay;
  197.  
  198. normalPay = wageRate * (hours - overtimeHrs);
  199. overtimePay = wageRate * OVERTIME_RATE * overtimeHrs;
  200. grossPay = normalPay + overtimePay;
  201.  
  202. return grossPay;
  203. }
  204.  
Success #stdin #stdout 0s 5316KB
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