fork(1) download
  1.  
  2. //*******************************************************
  3. //
  4. // Assignment 3 - Conditionals
  5. //
  6. // Name: <Felix Henriquez>
  7. //
  8. // Class: C Programming, <Fall 2025>
  9. //
  10. // Date: <9/28/2025>
  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. //********************************************************
  17.  
  18. #include <stdio.h>
  19.  
  20. // Declare constants
  21. #define STD_HOURS 40.0
  22. #define NUM_EMPLOYEES 5
  23. #define OVERTIME_RATE 1.5 // Time and a half for overtime
  24.  
  25. int main()
  26. {
  27. int clockNumber; // Employee clock number
  28. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  29. float hours; // Total hours worked in a week
  30. float normalPay; // Standard weekly normal pay without overtime
  31. float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
  32. float overtimePay; // Any hours worked past the normal scheduled work week
  33. float wageRate; // Hourly wage for an employee
  34.  
  35. printf("*** Pay Calculator ***\n");
  36.  
  37. // Process each employee
  38. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  39.  
  40. // Prompt the user for the clock number
  41. printf("\nEnter clock number: ");
  42. scanf("%d", &clockNumber);
  43.  
  44. // Prompt the user for the wage rate
  45. printf("Enter wage rate: ");
  46. scanf("%f", &wageRate);
  47.  
  48. // Prompt the user for the number of hours worked
  49. printf("Enter number of hours worked: ");
  50. scanf("%f", &hours);
  51.  
  52. // Calculate the overtime hours, normal pay, and overtime pay
  53. if (hours > STD_HOURS) {
  54. // Calculate with overtime
  55. overtimeHrs = hours - STD_HOURS;
  56. normalPay = STD_HOURS * wageRate;
  57. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  58. } else {
  59. // Calculate without overtime
  60. overtimeHrs = 0.0;
  61. normalPay = hours * wageRate;
  62. overtimePay = 0.0;
  63. }
  64.  
  65. // Calculate the gross pay with normal pay and any additional overtime pay
  66. grossPay = normalPay + overtimePay;
  67.  
  68. // Print out information on the current employee
  69. printf("\nClock# Wage Hours OT Gross\n");
  70. printf("-----------------------------------------\n");
  71. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  72. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  73. }
  74.  
  75. printf("\n*** All employees processed ***\n");
  76. return 0;
  77. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours  OT      Gross
-----------------------------------------
021863  0.00  -0.0   0.0     0.00

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours  OT      Gross
-----------------------------------------
021863  0.00  -0.0   0.0     0.00

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours  OT      Gross
-----------------------------------------
021863  0.00  -0.0   0.0     0.00

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours  OT      Gross
-----------------------------------------
021863  0.00  -0.0   0.0     0.00

Enter clock number: Enter wage rate: Enter number of hours worked: 
Clock#  Wage  Hours  OT      Gross
-----------------------------------------
021863  0.00  -0.0   0.0     0.00

*** All employees processed ***