fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: <Mario Morkus>
  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. float calcOvertimeHrs (float hours);
  29. float calcGrossPay (float hours, float wageRate, float overtimeHrs);
  30. void printHeader (void);
  31. void printEmp (long int clockNumber, float wageRate, float hours,
  32. float overtimeHrs, float grossPay);
  33.  
  34. int main()
  35. {
  36. /* Variable Declarations */
  37. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  38. float grossPay[SIZE];
  39. float hours[SIZE];
  40. int i;
  41. float overtimeHrs[SIZE];
  42. float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
  43.  
  44. // process each employee
  45. for (i = 0; i < SIZE; ++i)
  46. {
  47. // Read in hours for employee
  48. hours[i] = getHours(clockNumber[i]);
  49.  
  50. // Calculate overtime hours
  51. overtimeHrs[i] = calcOvertimeHrs(hours[i]);
  52.  
  53. // Calculate gross pay
  54. grossPay[i] = calcGrossPay(hours[i], wageRate[i], overtimeHrs[i]);
  55. }
  56.  
  57. // Print the header info
  58. printHeader();
  59.  
  60. // Print out each employee
  61. for (i = 0; i < SIZE; ++i)
  62. {
  63. printEmp(clockNumber[i], wageRate[i], hours[i],
  64. overtimeHrs[i], grossPay[i]);
  65. }
  66.  
  67. return (0);
  68.  
  69. } // main
  70.  
  71. //**************************************************************
  72. // Function: getHours
  73. //
  74. // Purpose: Obtains input from user, the number of hours worked
  75. // per employee and stores the result in a local variable
  76. // that is passed back to the calling function.
  77. //
  78. // Parameters: clockNumber - The unique employee ID
  79. //
  80. // Returns: hoursWorked - hours worked in a given week
  81. //
  82. //**************************************************************
  83. float getHours(long int clockNumber)
  84. {
  85. float hoursWorked;
  86.  
  87. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  88. scanf("%f", &hoursWorked);
  89.  
  90. return (hoursWorked);
  91.  
  92. } // getHours
  93.  
  94. //**************************************************************
  95. // Function: calcOvertimeHrs
  96. //
  97. // Purpose: Calculates the number of overtime hours worked by
  98. // an employee in a given week. If hours worked is at or below
  99. // the standard work week, overtime is zero.
  100. //
  101. // Parameters: hours - total hours worked in a given week
  102. //
  103. // Returns: overtimeHrs - the number of overtime hours worked
  104. //
  105. //**************************************************************
  106. float calcOvertimeHrs(float hours)
  107. {
  108. float overtimeHrs;
  109.  
  110. // Overtime is any hours above the standard work week
  111. if (hours > STD_WORK_WEEK)
  112. overtimeHrs = hours - STD_WORK_WEEK;
  113. else
  114. overtimeHrs = 0;
  115.  
  116. return (overtimeHrs);
  117.  
  118. } // calcOvertimeHrs
  119.  
  120. //**************************************************************
  121. // Function: calcGrossPay
  122. //
  123. // Purpose: Calculates the gross pay for an employee based on
  124. // their hours worked, wage rate, and overtime hours. Overtime
  125. // is paid at 1.5 times the normal wage rate.
  126. //
  127. // Parameters:
  128. //
  129. // hours - total hours worked in a given week
  130. // wageRate - hourly wage rate
  131. // overtimeHrs - overtime hours worked in a given week
  132. //
  133. // Returns: grossPay - the total gross pay for the week
  134. //
  135. //**************************************************************
  136. float calcGrossPay(float hours, float wageRate, float overtimeHrs)
  137. {
  138. float grossPay;
  139.  
  140. // Gross pay = standard pay + overtime pay (if any)
  141. if (overtimeHrs > 0)
  142. grossPay = (STD_WORK_WEEK * wageRate)
  143. + (overtimeHrs * wageRate * OVERTIME_RATE);
  144. else
  145. grossPay = hours * wageRate;
  146.  
  147. return (grossPay);
  148.  
  149. } // calcGrossPay
  150.  
  151. //**************************************************************
  152. // Function: printHeader
  153. //
  154. // Purpose: Prints the initial table header information.
  155. //
  156. // Parameters: none
  157. //
  158. // Returns: void
  159. //
  160. //**************************************************************
  161. void printHeader(void)
  162. {
  163. printf("\n\n*** Pay Calculator ***\n");
  164. printf("\nClock# Wage Hours OT Gross\n");
  165. printf("------------------------------------------------\n");
  166.  
  167. } // printHeader
  168.  
  169. //**************************************************************
  170. // Function: printEmp
  171. //
  172. // Purpose: Prints out all the information for an employee
  173. // in a nice and orderly table format.
  174. //
  175. // Parameters:
  176. //
  177. // clockNumber - unique employee ID
  178. // wageRate - hourly wage rate
  179. // hours - hours worked for the week
  180. // overtimeHrs - overtime hours worked in a week
  181. // grossPay - gross pay for the week
  182. //
  183. // Returns: void
  184. //
  185. //**************************************************************
  186. void printEmp(long int clockNumber, float wageRate, float hours,
  187. float overtimeHrs, float grossPay)
  188. {
  189. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  190. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  191.  
  192. } // printEmp
Success #stdin #stdout 0.01s 5276KB
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