fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: <Lavender Jane Siaw>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <3/10/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 calculateOvertimeHrs (float hours);
  34. float calculateGrossPay (float wageRate, float hours, float overtimeHrs);
  35.  
  36. int main()
  37. {
  38.  
  39. /* Variable Declarations */
  40.  
  41. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  42. float grossPay[SIZE]; // gross pay
  43. float hours[SIZE]; // hours worked in a given week
  44. int i; // loop and array index
  45. float overtimeHrs[SIZE]; // overtime hours
  46. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  47.  
  48. // process each employee
  49. for (i = 0; i < SIZE; ++i)
  50. {
  51.  
  52. // Read in hours for employee
  53. hours[i] = getHours (clockNumber[i]);
  54.  
  55. // TODO: Function call to calculate overtime hours
  56. overtimeHrs[i] = calculateOvertimeHrs (hours[i]);
  57.  
  58. // TODO: Function call to calculate gross pay
  59. grossPay[i] =calculateGrossPay (wageRate[i], hours[i], overtimeHrs[i]);
  60.  
  61. }
  62.  
  63. // print the header info
  64. printHeader();
  65.  
  66. // print out each employee
  67. for (i = 0; i < SIZE; ++i)
  68. {
  69.  
  70. // Print all the employees - call by value
  71. printEmp (clockNumber[i], wageRate[i], hours[i],
  72. overtimeHrs[i], grossPay[i]);
  73.  
  74. } // for
  75.  
  76. return (0);
  77.  
  78. } // main
  79.  
  80. //**************************************************************
  81. // Function: getHours
  82. //
  83. // Purpose: Obtains input from user, the number of hours worked
  84. // per employee and stores the result in a local variable
  85. // that is passed back to the calling function.
  86. //
  87. // Parameters: clockNumber - The unique employee ID
  88. //
  89. // Returns: hoursWorked - hours worked in a given week
  90. //
  91. //**************************************************************
  92.  
  93. float getHours (long int clockNumber)
  94. {
  95.  
  96. float hoursWorked; // hours worked in a given week
  97.  
  98. // Read in hours for employee
  99. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  100. if (scanf ("%f", &hoursWorked) != 1)
  101. {
  102. hoursWorked = 0.0f;
  103. }
  104.  
  105. // return hours back to the calling function
  106. return (hoursWorked);
  107.  
  108. } // getHours
  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.  
  124. printf ("\n\n*** Pay Calculator ***\n");
  125.  
  126. // print the table header
  127. printf("\nClock# Wage Hours OT Gross\n");
  128. printf("------------------------------------------------\n");
  129.  
  130. } // printHeader
  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.  
  156. printf("%06li $%5.2f %5.1f %5.1f $%7.2f\n",
  157. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  158.  
  159.  
  160. }
  161.  
  162.  
  163. // TODO: Add other functions here as needed
  164. // ... remember your comment block headers for each function
  165. float calculateOvertimeHrs (float hours)
  166. {
  167.  
  168. float othours = 0; // overtime hours to be calculated
  169.  
  170. // figure out othours
  171.  
  172. return (othours);
  173.  
  174. }
  175.  
  176.  
  177. float calculateGrossPay (float wageRate, float hours, float overtimeHrs)
  178. {
  179.  
  180. float grossPay = 0; // gross pay to be calculated
  181.  
  182. // figure out grossPay
  183.  
  184. return (grossPay);
  185.  
  186. }
  187.  
Success #stdin #stdout 0s 5320KB
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   0.0 $   0.00
526488 $ 9.75  42.5   0.0 $   0.00
765349 $10.50  37.0   0.0 $   0.00
034645 $12.25  45.0   0.0 $   0.00
127615 $ 8.35   0.0   0.0 $   0.00