fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Andrea Huskey
  6. //
  7. // Class: C Programming, Summer 2026
  8. // Date: June 26, 2026
  9. //
  10. // Description: Program which determines overtime and
  11. // gross pay for a set of employees with outputs sent
  12. // to standard output (the screen).
  13. //
  14. // All functions are called by value
  15. //
  16. //********************************************************
  17.  
  18. #include <stdio.h>
  19.  
  20. // constants
  21. #define SIZE 5
  22. #define OVERTIME_RATE 1.5f
  23. #define STD_WORK_WEEK 40.0f
  24.  
  25. // function prototypes
  26. float getHours (long int clockNumber);
  27. void printHeader (void);
  28. void printEmp (long int clockNumber, float wageRate, float hours,
  29. float overtimeHrs, float grossPay);
  30.  
  31. // TODO: Add other function prototypes here as needed
  32.  
  33. int main()
  34. {
  35.  
  36. /* Variable Declarations */
  37.  
  38. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  39. float grossPay[SIZE]; // gross pay = normal pay + ot pay
  40. float hours[SIZE]; // hours worked in a given week
  41. int i; // loop and array index
  42. float normalPay[SIZE]; // normal weekly pay without any overtime
  43. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  44. float overtimePay[SIZE] // overtime pay for a given week
  45.  
  46. //hourly pay for each employee
  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. // Calculate overtime and gross pay for employee
  57. if (hours[i] > STD_HOURS)
  58. {
  59. overtimeHrs[i] = hours[i] - STD_HOURS;
  60. // TODO: Function call to calculate gross pay
  61. normalPay[i] = STD_HOURS * wageRate[i];
  62. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  63. }
  64. else // no OT
  65. {
  66. overtimeHrs[i] = 0;
  67. // TODO: Calculate arrays normalPay and overtimePay without overtime
  68. normalPay[i] = hours[i] * wageRate[i];
  69. overtimePay[i] = 0.0;
  70. }
  71.  
  72.  
  73. }
  74.  
  75. // print the header info
  76. printHeader();
  77.  
  78. // print out each employee
  79. for (i = 0; i < SIZE; ++i)
  80. {
  81.  
  82. // Print all the employees - call by value
  83. printEmp (clockNumber[i], wageRate[i], hours[i],
  84. overtimeHrs[i], grossPay[i]);
  85.  
  86. } // for
  87.  
  88. return (0);
  89.  
  90. } // main
  91.  
  92. //**************************************************************
  93. // Function: getHours
  94. //
  95. // Purpose: Obtains input from user, the number of hours worked
  96. // per employee and stores the result in a local variable
  97. // that is passed back to the calling function.
  98. //
  99. // Parameters: clockNumber - The unique employee ID
  100. //
  101. // Returns: hoursWorked - hours worked in a given week
  102. //
  103. //**************************************************************
  104.  
  105. float getHours (long int clockNumber)
  106. {
  107.  
  108. float hoursWorked; // hours worked in a given week
  109.  
  110. // Read in hours for employee
  111. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  112. scanf ("%f", &hoursWorked);
  113.  
  114. // return hours back to the calling function
  115. return (hoursWorked);
  116.  
  117. } // getHours
  118.  
  119. //**************************************************************
  120. // Function: printHeader
  121. //
  122. // Purpose: Prints the initial table header information.
  123. //
  124. // Parameters: none
  125. //
  126. // Returns: void
  127. //
  128. //**************************************************************
  129.  
  130. void printHeader (void)
  131. {
  132.  
  133. printf ("\n\n*** Pay Calculator ***\n");
  134.  
  135. // print the table header
  136. printf("\nClock# Wage Hours OT Gross\n");
  137. printf("------------------------------------------------\n");
  138.  
  139. } // printHeader
  140.  
  141. //*************************************************************
  142. // Function: printEmp
  143. //
  144. // Purpose: Prints out all the information for an employee
  145. // in a nice and orderly table format.
  146. //
  147. // Parameters:
  148. //
  149. // clockNumber - unique employee ID
  150. // wageRate - hourly wage rate
  151. // hours - Hours worked for the week
  152. // overtimeHrs - overtime hours worked in a week
  153. // grossPay - gross pay for the week
  154. //
  155. // Returns: void
  156. //
  157. //**************************************************************
  158.  
  159. void printEmp (long int clockNumber, float wageRate, float hours,
  160. float overtimeHrs, float grossPay)
  161. {
  162.  
  163. // print the employee
  164.  
  165. // TODO: add code to print out a single employee
  166. }
  167.  
  168.  
  169. // TODO: Add other functions here as needed
  170. // ... remember your comment block headers for each function
Success #stdin #stdout 0s 5324KB
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
------------------------------------------------