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