fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Raissa Almeida Beckenkamp
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 12,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. // All functions called by reference
  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. void getHours (long int clockNumber[], float hours[], int theSize);
  28. void printHeader (void);
  29. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  30. float overtimeHrs[], float grossPay[], int theSize);
  31.  
  32. // TODO: Add other function prototypes here as needed
  33. float calcOT (float hours);
  34. float calcGross (float wageRate,
  35. float hours,
  36. float overtimeHrs);
  37.  
  38. int main()
  39. {
  40.  
  41. // Variable Declarations
  42.  
  43. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  44. float grossPay[SIZE]; // gross pay
  45. float hours[SIZE]; // hours worked in a given week
  46. int i; // loop and array index
  47. float overtimeHrs[SIZE]; // overtime hours
  48. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  49.  
  50. // Read in the hours worked for each employee
  51. getHours (clockNumber, hours, SIZE);
  52.  
  53. // TODO: Function call to calculate overtime hours
  54. overtimeHrs[i] = calcOT(hours[i]);
  55.  
  56. // TODO: Function call to calculate gross pay
  57. grossPay[i] = calcGross(hours[i], wageRate[i]);
  58.  
  59. // Print the initial table header
  60. printHeader ();
  61.  
  62. // Function call to output results to the screen
  63. printEmp (clockNumber, wageRate, hours,
  64. overtimeHrs, grossPay, SIZE);
  65.  
  66. return (0);
  67.  
  68. } // main
  69.  
  70. //***************************************************************
  71. // Function: getHours
  72. //
  73. // Purpose: Obtains input from user, the number of hours worked
  74. // per employee and stores the results in an array that is
  75. // passed back to the calling function by reference.
  76. //
  77. // Parameters:
  78. //
  79. // clockNumber - Array of employee clock numbers for each employee
  80. // hours - Array of hours worked by each employee
  81. // theSize - Number of employees to process
  82. //
  83. // Returns: Nothing (call by reference)
  84. //
  85. //**************************************************************
  86.  
  87. void getHours (long int clockNumber[], float hours[], int theSize)
  88. {
  89.  
  90. int i; // loop and array index
  91.  
  92. // Read in hours for each employee
  93. for (i= 0; i < theSize; ++i)
  94. {
  95. printf("\nEnter hours worked by emp # %06li: ", clockNumber[i]);
  96. scanf ("%f", &hours[i]);
  97. }
  98.  
  99. } // getHours
  100.  
  101. //**************************************************************
  102. // Function: printHeader
  103. //
  104. // Purpose: Prints the initial table header information.
  105. //
  106. // Parameters: none
  107. //
  108. // Returns: void
  109. //
  110. //**************************************************************
  111.  
  112. void printHeader (void)
  113. {
  114.  
  115. printf ("\n\n*** Pay Calculator ***\n");
  116.  
  117. // print the table header
  118. printf("\nClock# Wage Hours OT Gross\n");
  119. printf("------------------------------------------------\n");
  120.  
  121. } // printHeader
  122.  
  123. //**************************************************************
  124. // Function: printEmp
  125. //
  126. // Purpose: Prints out all the employee information in a
  127. // nice and orderly table format.
  128. //
  129. // Parameters:
  130. //
  131. // clockNumber - Array of employee clock numbers
  132. // wageRate - Array of employee wages per hour
  133. // hours - Array of number of hours worked by an employee
  134. // overtimeHrs - Array of overtime hours for each employee
  135. // grossPay - Array of gross pay calculations for each employee
  136. // theSize - Number of employees to process
  137. //
  138. // Returns: Nothing (call by reference)
  139. //
  140. //**************************************************************
  141.  
  142. void printEmp (long int clockNumber[], float wageRate[], float hours[],
  143. float overtimeHrs[], float grossPay[], int theSize)
  144. {
  145. int i; // loop and array index
  146.  
  147. // access and print each employee
  148. for (i = 0; i < theSize; ++i)
  149. {
  150. // TODO: add code to print out each employee one at a time
  151. printf("\t%06ld %5.2f %5.1f %5.1f %7.2f\n",
  152. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  153.  
  154. } // printEmp
  155. }
  156.  
  157. // TODO: Add other functions here as needed
  158. // ... remember your comment block headers for each function
  159.  
  160. //**************************************************************
  161. // Function: calcOT
  162. //
  163. // Purpose: Calculate overtime hours for a given week.
  164. // Overtime is any time worked over STD_WORK_WEEK.
  165. //
  166. // Parameters: hours - total hours worked in a given week
  167. //
  168. // Returns: overtime hours (0 if hours <= STD_WORK_WEEK)
  169. //
  170. //**************************************************************
  171. float calcOT(float hours)
  172. {
  173. if (hours > STD_WORK_WEEK)
  174. {
  175. return (hours - STD_WORK_WEEK);
  176. }
  177. else
  178. {
  179. return 0.0f;
  180. }
  181. }
  182.  
  183. //**************************************************************
  184. // Function: calcGross
  185. //
  186. // Purpose: Calculate gross pay using regular and overtime hours.
  187. // Regular hours are capped at STD_WORK_WEEK. Overtime
  188. // is paid at OVERTIME_RATE times the hourly wage.
  189. //
  190. // Parameters: hours - total hours worked in a given week
  191. // wage - hourly wage rate
  192. //
  193. // Returns: gross pay for the week
  194. //
  195. //**************************************************************
  196. float calcGross(float hours, float wage)
  197. {
  198. float regHours = hours;
  199. float otHours = 0.0f;
  200.  
  201. if (hours > STD_WORK_WEEK)
  202. {
  203. otHours = hours - STD_WORK_WEEK;
  204. regHours = STD_WORK_WEEK;
  205. }
  206.  
  207. return (regHours * wage) + (otHours * wage * OVERTIME_RATE);
  208. }
Compilation error #stdin compilation error #stdout 0s 5316KB
stdin
51.0
42.5
37.0
45.0
0.0
compilation info
prog.c: In function ‘main’:
prog.c:57:16: error: too few arguments to function ‘calcGross’
  grossPay[i] = calcGross(hours[i], wageRate[i]);
                ^~~~~~~~~
prog.c:34:7: note: declared here
 float calcGross (float wageRate,
       ^~~~~~~~~
prog.c: At top level:
prog.c:196:7: error: conflicting types for ‘calcGross’
 float calcGross(float hours, float wage)
       ^~~~~~~~~
prog.c:34:7: note: previous declaration of ‘calcGross’ was here
 float calcGross (float wageRate,
       ^~~~~~~~~
prog.c: In function ‘getHours’:
prog.c:96:9: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%f", &hours[i]);
         ^~~~~~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty