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. // Loop through for the number of employees
  35. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  36.  
  37. // Prompt the user for the clock number
  38. printf("\nEnter clock number: ");
  39. scanf("%d", &clock);
  40.  
  41. // Prompt the user for the wage rate
  42. printf("\nEnter wage rate: ");
  43. scanf("%f", &wage);
  44.  
  45. // Prompt the user for the number of hours worked
  46. printf("\nEnter number of hours worked: ");
  47. scanf("%f", &hours);
  48.  
  49. // TODO: For template ... remove at somepoint as really not needed
  50. grossPay = 0;
  51. overtimeHours = 0;
  52.  
  53. // Calculate the overtime hours, normal pay, and overtime pay
  54. if (hours > STD_HOURS) {
  55. /* TODO: calculate the three values with overtime */
  56. } else {
  57. /* TODO: calculate the three values without overtime */
  58. }
  59.  
  60. // Calculate the gross pay, including time and a half for overtime hours
  61. grossPay = normalPay + overtimePay;
  62.  
  63. // Display the clock number, number of hours, overtime hours, and gross pay, with the clock number padded with leading zeros if necessary
  64. printf("Clock# Wage Hours OT Gross\n");
  65. printf("------------------------------------------------\n");
  66. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  67. clock, wage, hours, overtimeHours, grossPay);
  68. }
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 5388KB
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
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