fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: MARTIN CLYTON MAYANJA
  6. //
  7. // Class: C Programming, Spring, 2026
  8. //
  9. // Date: 25FEB2026
  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.  
  34. float calcOT (float hours);
  35. float calcGross (float wageRate,float hours,float overtime);
  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. // TODO: Function call to calculate overtime hours
  57.  
  58. // Function call to calculate overtime hours
  59. overtimeHrs[i] = calcOT(hours[i]);
  60.  
  61.  
  62. // TODO: Function call to calculate gross pay
  63.  
  64. // Function call to calculate gross pay
  65. grossPay[i] =
  66. calcGross(wageRate[i],
  67. hours[i],
  68. overtimeHrs[i]);
  69.  
  70. }
  71.  
  72. // print the header info
  73. printHeader();
  74.  
  75.  
  76. // print out each employee
  77. for (i = 0; i < SIZE; ++i)
  78. {
  79.  
  80. // Print all the employees - call by value
  81. printEmp (clockNumber[i], wageRate[i], hours[i],
  82. overtimeHrs[i], grossPay[i]);
  83.  
  84. } // for
  85.  
  86. return (0);
  87.  
  88. } // main
  89.  
  90. //**************************************************************
  91. // Function: getHours
  92. //
  93. // Purpose: Obtains input from user, the number of hours worked
  94. // per employee and stores the result in a local variable
  95. // that is passed back to the calling function.
  96. //
  97. // Parameters: clockNumber - The unique employee ID
  98. //
  99. // Returns: hoursWorked - hours worked in a given week
  100. //
  101. //**************************************************************
  102.  
  103. float getHours (long int clockNumber)
  104. {
  105.  
  106. float hoursWorked; // hours worked in a given week
  107.  
  108. // Read in hours for employee
  109. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  110. scanf ("%f", &hoursWorked);
  111.  
  112. // return hours back to the calling function
  113. return (hoursWorked);
  114.  
  115. } // getHours
  116.  
  117. //**************************************************************
  118. // Function: printHeader
  119. //
  120. // Purpose: Prints the initial table header information.
  121. //
  122. // Parameters: none
  123. //
  124. // Returns: void
  125. //
  126. //**************************************************************
  127.  
  128. void printHeader (void)
  129. {
  130.  
  131. printf ("\n\n*** Pay Calculator ***\n");
  132.  
  133. // print the table header
  134. printf("\nClock# Wage Hours OT Gross\n");
  135. printf("------------------------------------------------\n");
  136.  
  137. } // printHeader
  138.  
  139. //*************************************************************
  140. // Function: printEmp
  141. //
  142. // Purpose: Prints out all the information for an employee
  143. // in a nice and orderly table format.
  144. //
  145. // Parameters:
  146. //
  147. // clockNumber - unique employee ID
  148. // wageRate - hourly wage rate
  149. // hours - Hours worked for the week
  150. // overtimeHrs - overtime hours worked in a week
  151. // grossPay - gross pay for the week
  152. //
  153. // Returns: void
  154. //
  155. //**************************************************************
  156.  
  157. void printEmp (long int clockNumber, float wageRate, float hours,
  158. float overtimeHrs, float grossPay)
  159. {
  160.  
  161. // print the employee
  162.  
  163. // TODO: add code to print out a single employee
  164.  
  165. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  166. clockNumber,
  167. wageRate,
  168. hours,
  169. overtimeHrs,
  170. grossPay);
  171.  
  172. }
  173.  
  174. // TODO: Add other functions here as needed
  175.  
  176.  
  177. //**************************************************************
  178. // Function: calcOT
  179. //
  180. // Purpose: Calculates overtime hours
  181. //
  182. //**************************************************************
  183.  
  184. float calcOT (float hours)
  185. {
  186.  
  187. float overtime;
  188.  
  189. if (hours > STD_WORK_WEEK)
  190. overtime = hours - STD_WORK_WEEK;
  191. else
  192. overtime = 0.0;
  193.  
  194. return overtime;
  195.  
  196. }
  197.  
  198. //**************************************************************
  199. // Function: calcGross
  200. //
  201. // Purpose: Calculates gross pay
  202. //
  203. //**************************************************************
  204.  
  205. float calcGross (float wageRate,
  206. float hours,
  207. float overtime)
  208. {
  209.  
  210. float regularPay;
  211. float overtimePay;
  212. float gross;
  213.  
  214. regularPay =
  215. wageRate * (hours - overtime);
  216.  
  217. overtimePay =
  218. overtime * wageRate * OVERTIME_RATE;
  219.  
  220. gross = regularPay + overtimePay;
  221.  
  222. return gross;
  223.  
  224. }
Success #stdin #stdout 0.01s 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