fork download
  1. //********************************************************
  2. //
  3. // Assignment 6 - Structures
  4. //
  5. // Name: Robert Liszka
  6. //
  7. // Class: C Programming, Spring. 2025
  8. //
  9. // Date: March 9, 2025
  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 reference 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 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.  
  44. void getHours (struct employee employeeData[], int theSize );
  45. void printHeader (void);
  46. void printEmp (struct employee emp [ ], int theSize);
  47.  
  48. // TODO: add your function prototypes here
  49.  
  50. void calcOT (struct employee employeeData [],
  51. int theSize);
  52. void calcGross (struct employee employeeData [],
  53. int theSize);
  54.  
  55. int main ()
  56. {
  57. // Set up a local variable and initialize the clock and wages of my employees
  58. struct employee employeeData [SIZE] = {
  59. { 98401, 10.60 },
  60. { 526488, 9.75 },
  61. { 765349, 10.50 },
  62. { 34645, 12.25 },
  63. { 127615, 8.35 }
  64. };
  65.  
  66. // Call function needed to read hours
  67. getHours (employeeData, SIZE);
  68.  
  69. // TODO: Call functions calculate ot hours and gross pay
  70. calcOT (employeeData, SIZE);
  71. calcGross (employeeData, SIZE);
  72. // TODO: Call function to print the table column headers
  73.  
  74. // Print a table header
  75. printHeader();
  76.  
  77. // Function call to output results to the screen in table format
  78. printEmp (employeeData, SIZE);
  79.  
  80. return(0); // success
  81.  
  82. } // main
  83.  
  84. //**************************************************************
  85. // Function: getHours
  86. //
  87. // Purpose: Obtains input from user, the number of hours worked
  88. // per employee and stores the result in an array of structures
  89. // that is passed back to the calling function by reference.
  90. //
  91. // Parameters:
  92. //
  93. // employeeData - an array of structures containing Employees
  94. // theSize - number of employees to process
  95. //
  96. // Returns: Nothing (void)
  97. //
  98. //**************************************************************
  99.  
  100. void getHours (struct employee employeeData[], int theSize )
  101. {
  102.  
  103. int i; // loop and array index
  104.  
  105. // read hours in for each employee
  106. for (i = 0; i < theSize ; ++i)
  107. {
  108. printf("\nEnter hours worked by emp # %06li: ",
  109. employeeData[i].clockNumber);
  110. scanf ("%f", &employeeData[i].hours);
  111. } // for
  112.  
  113. } // getHours
  114.  
  115. //**************************************************************
  116. // Function: printHeader
  117. //
  118. // Purpose: Prints the initial table header information.
  119. //
  120. // Parameters: none
  121. //
  122. // Returns: void
  123. //
  124. //**************************************************************
  125.  
  126. void printHeader (void)
  127. {
  128.  
  129. printf ("\n\n*** Pay Calculator ***\n");
  130.  
  131. // print the table header
  132. printf("\nClock# Wage Hours OT Gross\n");
  133. printf("------------------------------------------------\n");
  134.  
  135. } // printHeader
  136.  
  137. // ********************************************************************
  138. // Function: printEmp
  139. //
  140. // Purpose: Outputs to screen in a table format the following
  141. // information about an employee: Clock, Wage,
  142. // Hours, Overtime Hours, and Gross Pay.
  143. //
  144. // Parameters:
  145. //
  146. // employeeData - an array of structures containing Employees
  147. // theSize - number of employees to process
  148. //
  149. // Returns: Nothing (void)
  150. //
  151. // *********************************************************************
  152.  
  153. void printEmp ( struct employee employeeData[], int theSize )
  154. {
  155. int i; // loop and array index
  156.  
  157. // print information about each employee
  158. for (i = 0; i < theSize ; ++i)
  159. {
  160. printf("\n %06li %5.2f %4.1f %4.1f %8.2f",
  161. employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
  162. employeeData[i].overtimeHrs, employeeData[i].grossPay);
  163.  
  164. } /* for */
  165.  
  166. } // printEmp
  167.  
  168. // TODO: add your functions here
  169.  
  170. // Header
  171. void calcOT (struct employee employeeData [],
  172. int theSize)
  173. {
  174. int i;
  175.  
  176. for (i=0; I < SIZE; ++i)
  177. {
  178. // TODO: Add missing code
  179.  
  180. float overtimeHrs;
  181.  
  182. overtimeHrs = hours - STD_WORK_WEEK;
  183.  
  184. return (overtimeHrs);
  185.  
  186. } // for
  187.  
  188. }//calcOT
  189.  
  190.  
  191. //Header
  192. void calcGross (struct employee employeeData [],
  193. int theSize)
  194. {
  195.  
  196. int i; // loop and array index
  197. float normalPay; // normal pay earned
  198. float overtimePay
  199.  
  200. for (i=0; I < theSize; ++i)
  201. {
  202. // TODO: Add missing code
  203. if (hours > STD_WORK_WEEK)
  204. {
  205. // calculate overtime hours
  206. overtimeHrs = hours - STD_WORK_WEEK;
  207.  
  208. // calculate normal pay
  209. normalPay = STD_WORK_WEEK * wageRate;
  210.  
  211. // calculate overtime pay
  212. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  213.  
  214. }
  215. else
  216. {
  217. //they have no overtime hours
  218. overtimeHrs = 0;
  219. overtimePay = 0;
  220.  
  221. // calculate normal pay
  222. normalPay = hours * wageRate;
  223.  
  224. }// for if
  225.  
  226.  
  227. grossPay = normalPay + overtimePay;
  228.  
  229.  
  230. return(grossPay);
  231. } // for
  232.  
  233.  
  234. }//calcGross
Compilation error #stdin compilation error #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
compilation info
prog.c: In function ‘calcOT’:
prog.c:176:12: error: ‘I’ undeclared (first use in this function)
  for (i=0; I < SIZE; ++i)
            ^
prog.c:176:12: note: each undeclared identifier is reported only once for each function it appears in
prog.c:182:16: error: ‘hours’ undeclared (first use in this function)
  overtimeHrs = hours - STD_WORK_WEEK;
                ^~~~~
prog.c:182:24: error: ‘STD_WORK_WEEK’ undeclared (first use in this function)
  overtimeHrs = hours - STD_WORK_WEEK;
                        ^~~~~~~~~~~~~
prog.c:184:9: warning: ‘return’ with a value, in function returning void
  return (overtimeHrs);
         ^
prog.c:171:6: note: declared here
 void calcOT (struct employee employeeData [],
      ^~~~~~
prog.c: In function ‘calcGross’:
prog.c:200:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘for’
  for (i=0; I < theSize; ++i)
  ^~~
prog.c:200:12: error: ‘I’ undeclared (first use in this function)
  for (i=0; I < theSize; ++i)
            ^
prog.c:203:5: error: ‘hours’ undeclared (first use in this function)
 if (hours > STD_WORK_WEEK)
     ^~~~~
prog.c:203:13: error: ‘STD_WORK_WEEK’ undeclared (first use in this function)
 if (hours > STD_WORK_WEEK)
             ^~~~~~~~~~~~~
prog.c:206:3: error: ‘overtimeHrs’ undeclared (first use in this function)
   overtimeHrs = hours - STD_WORK_WEEK;
   ^~~~~~~~~~~
prog.c:209:31: error: ‘wageRate’ undeclared (first use in this function)
   normalPay = STD_WORK_WEEK * wageRate;
                               ^~~~~~~~
prog.c:212:3: error: ‘overtimePay’ undeclared (first use in this function)
   overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
   ^~~~~~~~~~~
prog.c:212:42: error: ‘OVERTIME_RATE’ undeclared (first use in this function); did you mean ‘OT_RATE’?
   overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
                                          ^~~~~~~~~~~~~
                                          OT_RATE
prog.c:227:2: error: ‘grossPay’ undeclared (first use in this function)
  grossPay = normalPay + overtimePay;
  ^~~~~~~~
prog.c:230:8: warning: ‘return’ with a value, in function returning void
  return(grossPay);
        ^
prog.c:192:6: note: declared here
 void calcGross (struct employee employeeData [],
      ^~~~~~~~~
prog.c: In function ‘getHours’:
prog.c:110:9: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%f", &employeeData[i].hours);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty