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