fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: David Morse
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: 2/26/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. // 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 calcOvertime (float hours);
  32. float calcGross (float wageRate, float hours, float overtimeHrs);
  33.  
  34. int main()
  35. {
  36.  
  37. /* Variable Declarations */
  38.  
  39. long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
  40. float grossPay[SIZE]; // gross pay
  41. float hours[SIZE]; // hours worked in a given week
  42. int i; // loop and array index
  43. float overtimeHrs[SIZE]; // overtime hours
  44. float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
  45.  
  46. // process each employee
  47. for (i = 0; i < SIZE; ++i)
  48. {
  49. // Read in hours for employee
  50. hours[i] = getHours (clockNumber[i]);
  51.  
  52. // Calculate overtime hours
  53. overtimeHrs[i] = calcOvertime(hours[i]);
  54.  
  55. // Calculate gross pay
  56. grossPay[i] = calcGross(wageRate[i], hours[i], overtimeHrs[i]);
  57. }
  58.  
  59. // print the header info
  60. printHeader();
  61.  
  62. // print out each employee
  63. for (i = 0; i < SIZE; ++i)
  64. {
  65. printEmp (clockNumber[i], wageRate[i], hours[i],
  66. overtimeHrs[i], grossPay[i]);
  67. }
  68.  
  69. return (0);
  70.  
  71. } // end main
  72.  
  73. //**************************************************************
  74. // Function: getHours
  75. //**************************************************************
  76. float getHours (long int clockNumber)
  77. {
  78. float hoursWorked; // hours worked in a given week
  79.  
  80. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  81. scanf ("%f", &hoursWorked);
  82.  
  83. return (hoursWorked);
  84.  
  85. } // end getHours
  86.  
  87. //**************************************************************
  88. // Function: calcOvertime
  89. //
  90. // Purpose: Calculates overtime hours worked.
  91. //
  92. // Parameters:
  93. // hours - total hours worked in week
  94. //
  95. // Returns:
  96. // overtime hours
  97. //**************************************************************
  98. float calcOvertime (float hours)
  99. {
  100. float overtime; // overtime hours
  101.  
  102. if (hours > STD_WORK_WEEK)
  103. overtime = hours - STD_WORK_WEEK;
  104. else
  105. overtime = 0.0f;
  106.  
  107. return overtime;
  108. }
  109.  
  110. //**************************************************************
  111. // Function: calcGross
  112. //
  113. // Purpose: Calculates gross pay including overtime.
  114. //
  115. // Parameters:
  116. // wageRate - hourly wage rate
  117. // hours - hours worked
  118. // overtimeHrs - overtime hours
  119. //
  120. // Returns:
  121. // gross pay
  122. //**************************************************************
  123. float calcGross (float wageRate, float hours, float overtimeHrs)
  124. {
  125. float regularPay; // regular pay
  126. float overtimePay; // overtime pay
  127. float gross; // total gross pay
  128.  
  129. regularPay = wageRate * (hours - overtimeHrs);
  130. overtimePay = wageRate * OVERTIME_RATE * overtimeHrs;
  131.  
  132. gross = regularPay + overtimePay;
  133.  
  134. return gross;
  135. }
  136.  
  137. //**************************************************************
  138. // Function: printHeader
  139. //**************************************************************
  140. void printHeader (void)
  141. {
  142. printf ("\n\n*** Pay Calculator ***\n");
  143. printf("\nClock# Wage Hours OT Gross\n");
  144. printf("------------------------------------------------\n");
  145. }
  146.  
  147. //**************************************************************
  148. // Function: printEmp
  149. //
  150. // Purpose: Prints employee payroll information in table format.
  151. //
  152. //**************************************************************
  153. void printEmp (long int clockNumber, float wageRate, float hours,
  154. float overtimeHrs, float grossPay)
  155. {
  156. printf("%06li %5.2f %5.1f %5.1f %8.2f\n",
  157. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  158. }
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