fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Carlos Dominguez
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: March 8th, 2026 -----------almost spring!
  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. #include <stdio.h>
  21.  
  22. // Define Constants
  23. #define SIZE 5
  24. #define STD_HOURS 40.0
  25. #define OT_RATE 1.5
  26.  
  27. // Define a global structure type to pass employee data between functions
  28. struct employee
  29. {
  30. long int clockNumber;
  31. float wageRate;
  32. float hours;
  33. float overtimeHrs;
  34. float grossPay;
  35. };
  36.  
  37. // Function Prototypes
  38. float getHours(long int clockNumber);
  39. void printHeader(void);
  40. void printEmp(long int clockNumber, float wageRate, float hours,
  41. float overtimeHrs, float grossPay);
  42.  
  43. // Added function prototypes
  44. float calcOvertime(float hours);
  45. float calcGross(float hours, float wageRate, float overtimeHrs);
  46.  
  47. int main()
  48. {
  49. // Local array of employee structures
  50. struct employee employeeData[SIZE] = {
  51. { 98401, 10.60 },
  52. { 526488, 9.75 },
  53. { 765349, 10.50 },
  54. { 34645, 12.25 },
  55. { 127615, 8.35 }
  56. };
  57.  
  58. int i; // loop index
  59.  
  60. // Loop through each employee and gather/calculate data
  61. for (i = 0; i < SIZE; ++i)
  62. {
  63. // Get hours worked for this employee
  64. employeeData[i].hours = getHours(employeeData[i].clockNumber);
  65.  
  66. // Calculate overtime hours
  67. employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
  68.  
  69. // Calculate gross pay
  70. employeeData[i].grossPay = calcGross(
  71. employeeData[i].hours,
  72. employeeData[i].wageRate,
  73. employeeData[i].overtimeHrs
  74. );
  75. }
  76.  
  77. // Print table header
  78. printHeader();
  79.  
  80. // Print each employee's data
  81. for (i = 0; i < SIZE; ++i)
  82. {
  83. printEmp(employeeData[i].clockNumber,
  84. employeeData[i].wageRate,
  85. employeeData[i].hours,
  86. employeeData[i].overtimeHrs,
  87. employeeData[i].grossPay);
  88. }
  89.  
  90. return 0; // success
  91. }
  92.  
  93. //**************************************************************
  94. // Function: getHours
  95. //
  96. // Purpose: Obtains input from user, the number of hours worked
  97. // per employee and stores the result in a local variable
  98. // that is passed back to the calling function.
  99. //
  100. // Parameters:
  101. // clockNumber - The unique employee ID
  102. //
  103. // Returns:
  104. // hoursWorked - hours worked in a given week
  105. //**************************************************************
  106.  
  107. float getHours(long int clockNumber)
  108. {
  109. float hoursWorked;
  110.  
  111. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  112. scanf("%f", &hoursWorked);
  113.  
  114. return hoursWorked;
  115. }
  116.  
  117. //**************************************************************
  118. // Function: printHeader
  119. //
  120. // Purpose: Prints the initial table header information.
  121. //
  122. // Parameters: none
  123. //
  124. // Returns: void
  125. //**************************************************************
  126.  
  127. void printHeader(void)
  128. {
  129. printf("\n\n*** Pay Calculator ***\n");
  130.  
  131. printf("\nClock# Wage Hours OT Gross\n");
  132. printf("------------------------------------------------\n");
  133. }
  134.  
  135. //*************************************************************
  136. // Function: printEmp
  137. //
  138. // Purpose: Prints out all the information for an employee
  139. // in a nice and orderly table format.
  140. //
  141. // Parameters:
  142. // clockNumber - unique employee ID
  143. // wageRate - hourly wage rate
  144. // hours - hours worked for the week
  145. // overtimeHrs - overtime hours worked
  146. // grossPay - gross pay for the week
  147. //
  148. // Returns: void
  149. //**************************************************************
  150.  
  151. void printEmp(long int clockNumber, float wageRate, float hours,
  152. float overtimeHrs, float grossPay)
  153. {
  154. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  155. clockNumber, wageRate, hours,
  156. overtimeHrs, grossPay);
  157. }
  158.  
  159. //**************************************************************
  160. // Function: calcOvertime
  161. //
  162. // Purpose: Calculates overtime hours based on STD_HOURS.
  163. //
  164. // Parameters:
  165. // hours - total hours worked
  166. //
  167. // Returns:
  168. // overtime hours (0 if none)
  169. //**************************************************************
  170.  
  171. float calcOvertime(float hours)
  172. {
  173. if (hours > STD_HOURS)
  174. return hours - STD_HOURS;
  175. else
  176. return 0.0;
  177. }
  178.  
  179. //**************************************************************
  180. // Function: calcGross
  181. //
  182. // Purpose: Calculates gross pay including overtime.
  183. //
  184. // Parameters:
  185. // hours - total hours worked
  186. // wageRate - hourly wage
  187. // overtimeHrs - overtime hours already calculated
  188. //
  189. // Returns:
  190. // gross pay for the week
  191. //**************************************************************
  192.  
  193. float calcGross(float hours, float wageRate, float overtimeHrs)
  194. {
  195. float normalPay;
  196. float overtimePay;
  197.  
  198. if (overtimeHrs > 0)
  199. {
  200. normalPay = STD_HOURS * wageRate;
  201. overtimePay = overtimeHrs * wageRate * OT_RATE;
  202. }
  203. else
  204. {
  205. normalPay = hours * wageRate;
  206. overtimePay = 0.0;
  207. }
  208.  
  209. return normalPay + overtimePay;
  210. }
Success #stdin #stdout 0.01s 5292KB
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