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