fork download
  1. //********************************************************
  2. //
  3. // Assignment 5 - Functions
  4. //
  5. // Name: Jalen Tam
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 10, 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 STD_HOURS 40
  24. #define OVT_RATE 1.5
  25.  
  26. // Function prototypes
  27. float getHours (int clockNumber);
  28. float overtimeHours (float hoursWorked);
  29. float getRegularPay (float hours, float wage);
  30. float getOvertimePay (float hours, float wage);
  31.  
  32. // FUNCTION getHours
  33. // Prompt for hours worked
  34. // Parameters: clockNumber - Employee clock number
  35. // Returns: Hours worked
  36. float getHours (int clockNumber) {
  37.  
  38. //Initialize hours worked
  39. float hoursWorked;
  40.  
  41. //Prompts hour worked and scans it into hoursWorked variable
  42. //printf ("Enter hours worked for %06i ", clockNumber);
  43. scanf ("%f", &hoursWorked);
  44.  
  45. return hoursWorked;
  46.  
  47. }
  48.  
  49. // FUNCTION getOvertimeHours
  50. // Calculates overtime hours worked
  51. // Parameters: hoursWorked - hours worked
  52. // Returns: overtime hours
  53. float getOvertimeHours (float hoursWorked) {
  54.  
  55. //Initialize overtime hours worked variable
  56. float ovtHours;
  57.  
  58. //calculating overtime hours
  59. //If hours worked is more than 40
  60. if (hoursWorked > STD_HOURS){
  61. ovtHours = hoursWorked - STD_HOURS;
  62. }
  63. //Hours worked is less than 40 hours
  64. else {
  65. ovtHours = 0;
  66. }
  67. return ovtHours;
  68.  
  69. }
  70.  
  71.  
  72. // FUNCTION getRegularPay
  73. // Calculates pay for regular hours worked
  74. // Parameters: hours - total hours worked, wage - wage rate per regular hour worked
  75. // Returns: regular pay
  76. float getRegularPay (float hours, float wage) {
  77.  
  78. //Initialize regular pay variable
  79. float regPay;
  80.  
  81. if (hours > STD_HOURS) { //Calculates pay if overtime is worked
  82. regPay = STD_HOURS * wage;
  83. }
  84. else { //Calculates pay if no overtime
  85. regPay = hours * wage;
  86. }
  87.  
  88. //returns pay for regular wage rate
  89. return regPay;
  90.  
  91. }
  92.  
  93. // FUNCTION getOvertimePay
  94. // Calculates pay for overtime hours worked
  95. // Parameters: hours - overtime hours worked, wage - wage rate per regular hour worked
  96. // Returns: overtime pay
  97. float getOvertimePay (float hours, float wage) {
  98.  
  99. float ovtPay;
  100. ovtPay = hours * (wage * OVT_RATE);
  101. return ovtPay;
  102.  
  103. }
  104.  
  105. // FUNCTION getGrossPay
  106. // Calculates gross pay for regular and overtime hours worked
  107. // Parameters: ovtPay - overtime pay, regPay - regular pay
  108. // Returns: gross pay
  109. float getGrossPay (float ovtPay, float regPay) {
  110.  
  111. float gross;
  112. gross = ovtPay + regPay;
  113. return gross;
  114.  
  115. }
  116.  
  117. int main() {
  118.  
  119. int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615}; //Clock number array
  120. float wageRate [SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35}; //Wage rate array
  121. float hoursWorked [SIZE] = {}; //Initialize hours worked array
  122. float overtimeHours [SIZE] = {}; //Initialize overtime hours array
  123. float regularPay [SIZE] = {}; //Initialize regular pay array
  124. float overtimePay [SIZE] = {}; //Initialize overtime pay array
  125. float grossPay [SIZE] = {}; //Initialize gross pay array
  126.  
  127. printf("Clock# Wage Hours OT Reg Pay OT Pay Gross\n");
  128. printf("---------------------------------------------------------\n");
  129.  
  130. int i;
  131. for (i = 0; i < SIZE; ++i){
  132. hoursWorked[i] = getHours(clockNumber[i]);
  133. overtimeHours[i] = getOvertimeHours(hoursWorked[i]);
  134. regularPay[i] = getRegularPay(hoursWorked[i], wageRate[i]);
  135. overtimePay[i] = getOvertimePay(overtimeHours[i], wageRate[i]);
  136. grossPay[i] = getGrossPay(overtimePay[i], regularPay[i]);
  137. printf("%06i\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n", clockNumber[i], wageRate[i], hoursWorked[i], overtimeHours[i], regularPay[i], overtimePay[i], grossPay[i]);
  138.  
  139. }
  140.  
  141.  
  142.  
  143. return 0;
  144.  
  145. }
Success #stdin #stdout 0.01s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
Clock#	Wage	Hours	 OT 	Reg Pay	 OT Pay	 Gross
---------------------------------------------------------
098401	 10.60	 51.00	 11.00	 424.00	 174.90	 598.90
526488	 9.75	 42.50	 2.50	 390.00	 36.56	 426.56
765349	 10.50	 37.00	 0.00	 388.50	 0.00	 388.50
034645	 12.25	 45.00	 5.00	 490.00	 91.88	 581.88
127615	 8.35	 0.00	 0.00	 0.00	 0.00	 0.00