fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Dani D'Oleo Pena
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: 06/24/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 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. float getOThours (float hours, float stdworkweek);
  32. float calculateGrossPay(float hours, float wageRate, float otwageRate, float othours, float stdworkweek);
  33.  
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39.  
  40. /* Variable Declarations */
  41.  
  42. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  43. float grossPay[SIZE]; // gross pay
  44. float hours[SIZE]; // hours worked in a given week
  45. int i; // loop and array index
  46. float overtimeHrs[SIZE]; // overtime hours
  47. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  48.  
  49. // process each employee
  50. for (i = 0; i < SIZE; ++i)
  51. {
  52.  
  53. // Read in hours for employee
  54. hours[i] = getHours (clockNumber[i]);
  55.  
  56. overtimeHrs[i] = getOThours (hours[i], STD_WORK_WEEK);
  57. // TODO: Function call to calculate gross pay
  58. grossPay[i] = calculateGrossPay(hours[i], wageRate[i], OVERTIME_RATE, overtimeHrs[i], STD_WORK_WEEK);
  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.  
  107. //**************************************************************
  108. // Function: getOTHours
  109. //
  110. // Purpose: Obtains number of Overtime hours based on the amount of hours worked.
  111. //
  112. // Parameters: hours - numbers of hours worked, stdworkweek - amount of hours worked without overtime
  113. //
  114. // Returns: othoursWorked - overtime hours worked in a given week
  115. //
  116. //**************************************************************
  117.  
  118. float getOThours (float hours, float stdworkweek)
  119. {
  120. float othoursWorked = hours - stdworkweek;
  121. if (othoursWorked > 0.0) { //checks if there is overtime or not.
  122. return (othoursWorked);
  123. }
  124. else {
  125. return (0);
  126. }
  127. } // getOThours
  128.  
  129.  
  130. //**************************************************************
  131. // Function: calculateGrossPay
  132. //
  133. // Purpose: Obtains Gross pay based on wage rates
  134. //
  135. // Parameters: hours - numbers of hours worked, wageRate - normal wage rate, otwageRate - overtime wage rate,
  136. // othours - numbers of overtime hours worked.
  137. //
  138. // Returns: grossPay - total money gained from working.
  139. //
  140. //**************************************************************
  141.  
  142. float calculateGrossPay(float hours, float wageRate, float otwageRate, float othours, float stdworkweek)
  143. {
  144. float grossPay;
  145. if (othours != 0){ // if there is overtime calculate grosspay with overtime
  146. grossPay = stdworkweek*wageRate + otwageRate*wageRate*othours;
  147. }
  148. else { // if there isn't overtime calculate grosspay without overtime
  149. grossPay = hours*wageRate;
  150. }
  151. return (grossPay);
  152.  
  153. } // calculateGrossPay
  154.  
  155.  
  156. //**************************************************************
  157. // Function: printHeader
  158. //
  159. // Purpose: Prints the initial table header information.
  160. //
  161. // Parameters: none
  162. //
  163. // Returns: void
  164. //
  165. //**************************************************************
  166.  
  167. void printHeader (void)
  168. {
  169.  
  170. printf ("\n\n*** Pay Calculator ***\n");
  171.  
  172. // print the table header
  173. printf("\nClock# Wage Hours OT Gross\n");
  174. printf("------------------------------------------------\n");
  175.  
  176. } // printHeader
  177.  
  178. //*************************************************************
  179. // Function: printEmp
  180. //
  181. // Purpose: Prints out all the information for an employee
  182. // in a nice and orderly table format.
  183. //
  184. // Parameters:
  185. //
  186. // clockNumber - unique employee ID
  187. // wageRate - hourly wage rate
  188. // hours - Hours worked for the week
  189. // overtimeHrs - overtime hours worked in a week
  190. // grossPay - gross pay for the week
  191. //
  192. // Returns: void
  193. //
  194. //**************************************************************
  195.  
  196. void printEmp (long int clockNumber, float wageRate, float hours,
  197. float overtimeHrs, float grossPay)
  198. {
  199. // print the employee
  200. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
  201.  
  202. }
  203.  
  204.  
  205.  
Success #stdin #stdout 0s 5320KB
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