fork(1) download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: J. Student
  6. //
  7. // Class: C Programming, Spring 2023
  8. //
  9. // Date: 2/10/23
  10. //
  11. // Description: Program which determines overtime and gross pay for
  12. // a set of employees and outputs are sent to standard output (the screen).
  13. //
  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.  
  24. int main() {
  25.  
  26. int clock; // Employee clock number
  27. float wage; // Hourly wage for an employee
  28. float hours; // Total hours worked in a week
  29. float normalPay; // Standard weekly normal pay without overtime
  30. float overtimeHours; // Overtime hours counted over 40 a week
  31. float overtimePay; // Additional overtime pay for any overtime hours worked
  32. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  33.  
  34. printf ("\n*** Pay Calculator ***");
  35.  
  36. // Loop through for the number of employees
  37. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  38.  
  39.  
  40. // Prompt the user for the clock number
  41. printf("\n\nEnter clock number: ");
  42. scanf("%d", &clock);
  43.  
  44. // Prompt the user for the wage rate
  45. printf("\nEnter wage rate: ");
  46. scanf("%f", &wage);
  47.  
  48. // Prompt the user for the number of hours worked
  49. printf("\nEnter number of hours worked: ");
  50. scanf("%f", &hours);
  51.  
  52. // TODO: For template ... remove at somepoint as really not needed
  53. grossPay = 0;
  54. overtimeHours = 0;
  55.  
  56. // Calculate the overtime hours, normal pay, and overtime pay
  57. if (hours > STD_HOURS) {
  58. /* TODO: calculate the three values with overtime */
  59. } else {
  60. /* TODO: calculate the three values without overtime */
  61. }
  62.  
  63. // Calculate the gross pay, including time and a half for overtime hours
  64. grossPay = normalPay + overtimePay;
  65.  
  66. // Display the clock number, number of hours, overtime hours, and gross pay, with the clock number padded with leading zeros if necessary
  67. printf("\n\nClock# Wage Hours OT Gross\n");
  68. printf("------------------------------------------------\n");
  69. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  70. clock, wage, hours, overtimeHours, grossPay);
  71. }
  72.  
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0s 5520KB
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   0.0     0.00


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
526488  9.75  42.5   0.0     0.00


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

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


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
034645 12.25  45.0   0.0     0.00


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