fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Andrea Huskey
  6. //
  7. // Class: C Programming, Summer 2026
  8. //
  9. // Date: June 29, 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. // Call by Value design
  16. //
  17. //********************************************************
  18.  
  19. // Define and Includes
  20.  
  21. #include <stdio.h>
  22.  
  23. // Define Constants
  24. #define SIZE 5
  25. #define STD_HOURS 40.0
  26. #define OT_RATE 1.5
  27.  
  28. // Define a global structure to pass employee data between functions
  29. // Note that the structure type is global, but you don't want a variable
  30. // of that type to be global. Best to declare a variable of that type
  31. // in a function like main or another function and pass as needed.
  32.  
  33. struct employee
  34. {
  35. long int clockNumber;
  36. float wageRate;
  37. float hours;
  38. float overtimeHrs;
  39. float grossPay;
  40. };
  41.  
  42. // define prototypes here for each function except main
  43. void getHours (long int clockNumber [], float hours [], int theSize);
  44. void printHeader (void);
  45. void printEmp (long int clockNumber [], float wageRate [], float hours [],
  46. float overtimeHrs [], float grossPay []);
  47. void calcOT (float hours [], float overtimerHrs [], int theSize);
  48. void calcGross (float wageRate [], float hours [], float [], float overtimeHrs []);
  49.  
  50. // TODO: Add your other function prototypes here
  51.  
  52. // write function for overtime hours math
  53. // lets attempt it.
  54. int OThours (int hours, int stdhours)
  55. {
  56. int result = hours - stdhours;
  57. return result;
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. int main ()
  65. {
  66. // Set up a local variable to store the employee information
  67. struct employee employeeData[SIZE] = {
  68. { 98401, 10.60 },
  69. { 526488, 9.75 },
  70. { 765349, 10.50 }, // initialize clock and wage values
  71. { 34645, 12.25 },
  72. { 127615, 8.35 }
  73. };
  74.  
  75. int i; // loop and array index
  76.  
  77. // Call functions as needed to read and calculate information
  78. for (i = 0; i < SIZE; ++i)
  79. {
  80.  
  81. // Prompt for the number of hours worked by the employee
  82. employeeData[i].hours = getHours (employeeData[i].clockNumber);
  83.  
  84. // TODO: Add other function calls as needed to calculate overtime and gross
  85.  
  86. } // for
  87.  
  88. // Print the column headers
  89. printHeader();
  90.  
  91. // print out each employee
  92. for (i = 0; i < SIZE; ++i)
  93. {
  94. printEmp (employeeData[i].clockNumber,
  95. employeeData[i].wageRate,
  96. employeeData[i].hours,
  97. employeeData[i].overtimeHrs,
  98. employeeData[i].grossPay);
  99. }
  100.  
  101. return(0); // success
  102.  
  103. } // main
  104.  
  105. //**************************************************************
  106. // Function: getHours
  107. //
  108. // Purpose: Obtains input from user, the number of hours worked
  109. // per employee and stores the result in a local variable
  110. // that is passed back to the calling function.
  111. //
  112. // Parameters: clockNumber - The unique employee ID
  113. //
  114. // Returns: hoursWorked - hours worked in a given week
  115. //
  116. //**************************************************************
  117.  
  118. float getHours (long int clockNumber)
  119. {
  120.  
  121. float hoursWorked; // hours worked in a given week
  122.  
  123. // Read in hours for employee
  124. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  125. scanf ("%f", &hoursWorked);
  126.  
  127. // return hours back to the calling function
  128. return (hoursWorked);
  129.  
  130. } // getHours
  131.  
  132. //**************************************************************
  133. // Function: printHeader
  134. //
  135. // Purpose: Prints the initial table header information.
  136. //
  137. // Parameters: none
  138. //
  139. // Returns: void
  140. //
  141. //**************************************************************
  142.  
  143. void printHeader (void)
  144. {
  145.  
  146. printf ("\n\n*** Pay Calculator ***\n");
  147.  
  148. // print the table header
  149. printf("\nClock# Wage Hours OT Gross\n");
  150. printf("------------------------------------------------\n");
  151.  
  152. } // printHeader
  153.  
  154.  
  155. //*************************************************************
  156. // Function: printEmp
  157. //
  158. // Purpose: Prints out all the information for an employee
  159. // in a nice and orderly table format.
  160. //
  161. // Parameters:
  162. //
  163. // clockNumber - unique employee ID
  164. // wageRate - hourly wage rate
  165. // hours - Hours worked for the week
  166. // overtimeHrs - overtime hours worked in a week
  167. // grossPay - gross pay for the week
  168. //
  169. // Returns: void
  170. //
  171. //**************************************************************
  172.  
  173. void printEmp (long int clockNumber, float wageRate, float hours,
  174. float overtimeHrs, float grossPay)
  175. {
  176.  
  177. // Print out a single employee
  178. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  179. clockNumber, wageRate, hours,
  180. overtimeHrs, grossPay);
  181.  
  182. } // printEmp
  183.  
  184. // TODO: Add your functions here
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
------------------------------------------------

 098401 10.60 51.0  0.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     0.00