fork 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 normalPay, float overtimePay, 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_WORK_WEEK)
  58. {
  59. overtimeHrs[i] = hours[i] - STD_WORK_WEEK;
  60.  
  61. // TODO: Function call to calculate gross pay, added normalPay and overtimePay
  62. normalPay[i] = STD_WORK_WEEK * wageRate[i];
  63. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OVERTIME_RATE;
  64. }
  65. else // no OT
  66. {
  67. overtimeHrs[i] = 0.0f;
  68.  
  69. // TODO: Calculate arrays normalPay and overtimePay without overtime
  70. normalPay[i] = hours[i] * wageRate[i];
  71. overtimePay[i] = 0.0f;
  72. }
  73.  
  74. //Calculate gross pay
  75. grossPay[i] = normalPay[i] + overtimePay[i];
  76.  
  77. }
  78.  
  79. // print the header info
  80. printHeader();
  81.  
  82. // print out each employee
  83. for (i = 0; i < SIZE; ++i)
  84. {
  85.  
  86. // Print all the employees - call by value
  87. printEmp (clockNumber[i], wageRate[i], hours[i],
  88. overtimeHrs[i], normalPay[i], overtimePay[i], grossPay[i]);
  89.  
  90. } // for
  91.  
  92. return (0);
  93.  
  94. } // main
  95.  
  96. //**************************************************************
  97. // Function: getHours
  98. //
  99. // Purpose: Obtains input from user, the number of hours worked
  100. // per employee and stores the result in a local variable
  101. // that is passed back to the calling function.
  102. //
  103. // Parameters: clockNumber - The unique employee ID
  104. //
  105. // Returns: hoursWorked - hours worked in a given week
  106. //
  107. //**************************************************************
  108.  
  109. float getHours (long int clockNumber)
  110. {
  111.  
  112. float hoursWorked; // hours worked in a given week
  113.  
  114. // Read in hours for employee
  115. printf("Enter hours worked by emp # %06li: ", clockNumber);
  116. scanf ("%f", &hoursWorked);
  117.  
  118. // return hours back to the calling function
  119. return (hoursWorked);
  120.  
  121. } // getHours
  122.  
  123. //**************************************************************
  124. // Function: printHeader
  125. //
  126. // Purpose: Prints the initial table header information.
  127. //
  128. // Parameters: none
  129. //
  130. // Returns: void
  131. //
  132. //**************************************************************
  133.  
  134. void printHeader (void)
  135. {
  136.  
  137. printf ("\n\n*** Pay Calculator ***\n");
  138.  
  139. // print the table header
  140. printf("\n%-8s %-6s %-6s %-5s %-10s %-8s %-8s\n",
  141. "Clock#", "Wage", "Hours", "OT", "NormalPay", "OTpay", "Gross");
  142. printf("------------------------------------------------=========\n");
  143.  
  144. } // printHeader
  145.  
  146. //*************************************************************
  147. // Function: printEmp
  148. //
  149. // Purpose: Prints out all the information for an employee
  150. // in a nice and orderly table format.
  151. //
  152. // Parameters:
  153. //
  154. // clockNumber - unique employee ID
  155. // wageRate - hourly wage rate
  156. // hours - Hours worked for the week
  157. // overtimeHrs - overtime hours worked in a week
  158. // added normalPay - normal weekly pay
  159. // added overtimePay - overtime pay for the week
  160. // grossPay - gross pay for the week
  161. //
  162. // Returns: void
  163. //
  164. //**************************************************************
  165.  
  166. void printEmp (long int clockNumber, float wageRate, float hours,
  167. float overtimeHrs, float normalPay, float overtimePay, float grossPay)
  168. {
  169.  
  170. // print the employee
  171. printf("%06li %-6.2f %-6.1f %-5.1f %-10.2f %-8.2f %-8.2f\n",
  172. clockNumber, wageRate, hours, overtimeHrs, normalPay, overtimePay, grossPay);
  173.  
  174. }
  175.  
  176.  
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    NormalPay  OTpay    Gross   
------------------------------------------------=========
098401	 10.60  51.0   11.0  424.00     174.90   598.90  
526488	 9.75   42.5   2.5   390.00     36.56    426.56  
765349	 10.50  37.0   0.0   388.50     0.00     388.50  
034645	 12.25  45.0   5.0   490.00     91.88    581.88  
127615	 8.35   0.0    0.0   0.00       0.00     0.00