fork(2) download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Brian Fallon
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: February 12, 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. //********************************************************
  16.  
  17. #include <stdio.h>
  18.  
  19. // Declare constants
  20. #define STD_HOURS 40.0
  21. #define NUM_EMPLOYEES 5
  22. // TODO: Declare and use one more constant
  23. #define OT_RATE 1.5
  24.  
  25. int main()
  26. {
  27.  
  28. int clockNumber; // Employee clock number
  29. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  30. float hoursTotal; // Total hours worked in a week
  31. float normalPay; // Standard weekly normal pay without overtime
  32. float overtimeHrs; // Any hours worked past the normal scheduled work week
  33. float overtimePay; // Additional overtime pay for any overtime hours worked
  34. float wageRate; // Hourly wage for an employee
  35.  
  36. printf ("\n*** Pay Calculator ***");
  37.  
  38. // Process each employee
  39. for (int i = 0; i < NUM_EMPLOYEES; i++)
  40. {
  41.  
  42. // Prompt the user for the clock number
  43. printf("\n\nEnter clock number: ");
  44. scanf("%d", &clockNumber);
  45.  
  46. // Prompt the user for the wage rate
  47. printf("\nEnter wage rate: ");
  48. scanf("%f", &wageRate);
  49.  
  50. // Prompt the user for the number of hours worked
  51. printf("\nEnter number of hours worked: ");
  52. scanf("%f", &hoursTotal);
  53.  
  54. // Optional TODO: Remove these two statements if desired
  55. // ... were added just for the template to print some values out of the box
  56. grossPay = 0;
  57. overtimeHrs = 0;
  58.  
  59. // Calculate the overtime hours, normal pay, and overtime pay
  60. if (hoursTotal > STD_HOURS)
  61. {
  62. overtimeHrs = hoursTotal - STD_HOURS;
  63. overtimePay = overtimeHrs * (OT_RATE*wageRate);
  64. normalPay= STD_HOURS * wageRate; // TODO: calculate the three values with overtime
  65. } //End if
  66. else
  67. {
  68. overtimePay=0;
  69. normalPay=wageRate*hoursTotal; // TODO: calculate the two values without overtime
  70. } //End else
  71.  
  72. // Calculate the gross pay with normal pay and any additional overtime pay
  73. grossPay = normalPay + overtimePay;
  74.  
  75. // Print out information on the current employee
  76. // Optional TODO: Feel free to also print out normalPay and overtimePay
  77. printf("\n\nClock# Wage Hours OT Gross\n");
  78. printf("------------------------------------------------\n");
  79. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  80. clockNumber, wageRate, hoursTotal, overtimeHrs, grossPay);
  81. } //End for
  82.  
  83. return 0;
  84. } //End main
Success #stdin #stdout 0s 5284KB
stdin
98401 10.60 51.0
526488 9.75 42.5
765349 10.50 37.0
34645 12.25 45.0
127615 8.35 0.0
stdout
*** Pay Calculator ***

Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage  Hours  OT      Gross
------------------------------------------------
098401 10.60  51.0  11.0   598.90


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage  Hours  OT      Gross
------------------------------------------------
526488  9.75  42.5   2.5   426.56


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage  Hours  OT      Gross
------------------------------------------------
765349 10.50  37.0   0.0   388.50


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage  Hours  OT      Gross
------------------------------------------------
034645 12.25  45.0   5.0   581.88


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage  Hours  OT      Gross
------------------------------------------------
127615  8.35   0.0   0.0     0.00