fork(1) download
  1.  
  2. //********************************************************
  3. //
  4. // Assignment 5 - Functions
  5. //
  6. // Name: <Isaac Boahndao>
  7. //
  8. // Class: C Programming, <Spring Semester and 2025>
  9. //
  10. // Date: <03_02_25>
  11. //
  12. // Description: Program which determines overtime and
  13. // gross pay for a set of employees with outputs sent
  14. // to standard output (the screen).
  15. //
  16. // All functions are called by value
  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 calculateOvertime(float hours);
  32. float calculateGrossPay(float wageRate, float hours, float overtimeHrs);
  33.  
  34. int main() {
  35. // Variable Declarations
  36. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // ID
  37. float grossPay[SIZE]; // Gross pay
  38. float hours[SIZE]; // Hours worked in a given week
  39. float overtimeHrs[SIZE]; // Overtime hours
  40. float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35}; // Hourly wage rate
  41. int i; // Loop index
  42.  
  43. // Process each employee
  44. for (i = 0; i < SIZE; ++i) {
  45. hours[i] = getHours(clockNumber[i]);
  46. overtimeHrs[i] = calculateOvertime(hours[i]);
  47. grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
  48. }
  49.  
  50. // Print the header info
  51. printHeader();
  52.  
  53. // Print out each employee's details
  54. for (i = 0; i < SIZE; ++i) {
  55. printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61. // Function to get hours worked from user
  62. float getHours(long int clockNumber) {
  63. float hoursWorked;
  64. printf("\nEnter hours worked by emp # %06li: ", clockNumber);
  65. scanf("%f", &hoursWorked);
  66. return hoursWorked;
  67. }
  68.  
  69. // Function to print the table header
  70. void printHeader(void) {
  71. printf("\n*** Pay Calculator ***\n\n");
  72. printf("Clock# Wage Hours OT Gross\n");
  73. printf("------------------------------------\n");
  74. }
  75.  
  76. // Function to print employee details
  77. void printEmp(long int clockNumber, float wageRate, float hours,
  78. float overtimeHrs, float grossPay) {
  79. printf("%06li %.2f %.2f %.2f %.2f\n",
  80. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  81. }
  82.  
  83. // Function to calculate overtime hours
  84. float calculateOvertime(float hours) {
  85. return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
  86. }
  87.  
  88. // Function to calculate gross pay
  89. float calculateGrossPay(float wageRate, float hours, float overtimeHrs) {
  90. float regularPay = wageRate * (hours - overtimeHrs);
  91. float overtimePay = overtimeHrs * (wageRate * OVERTIME_RATE);
  92. return regularPay + overtimePay;
  93. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
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  0.00  0.00  0.00
526488  9.75  0.00  0.00  0.00
765349  10.50  0.00  0.00  0.00
034645  12.25  0.00  0.00  0.00
127615  8.35  0.00  0.00  0.00