fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: John Eneh
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 9/27/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. #define OVERTIME_RATE 1.5 // $1.5 per hour is an unchanging rate of pay
  23.  
  24. int main()
  25. {
  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; // Any hours worked past the normal scheduled work week
  32. float overtimePay; // Additional overtime pay for any overtime hours worked
  33. float wageRate; // Hourly wage for an employee
  34.  
  35. printf ("\n*** Pay Calculator ***");
  36.  
  37. // Process each employee
  38. for (int i = 0; i < NUM_EMPLOYEES; i++)
  39. {
  40.  
  41. // Prompt the user for the clock number
  42. printf("\n\nEnter clock number: ");
  43. scanf("%d", &clockNumber);
  44.  
  45. // Prompt the user for the wage rate
  46. printf("\nEnter wage rate: ");
  47. scanf("%f", &wageRate);
  48.  
  49. // Prompt the user for the number of hours worked
  50. printf("\nEnter number of hours worked: ");
  51. scanf("%f", &hours);
  52.  
  53. // Calculate the overtime hours, normal pay, and overtime pay
  54. if (hours > STD_HOURS)
  55. {
  56. overtimeHrs = hours - STD_HOURS; /* overtime is more than 40 work hrs */
  57. normalPay = wageRate * (hours - overtimeHrs); /* Removing any overtime hours to get the correct normal pay */
  58. overtimePay = overtimeHrs * (wageRate * OVERTIME_RATE); /* overtime pay is x1.5 for every extra hour */
  59. }
  60. else
  61. {
  62. overtimeHrs = 0; /* there is no overtime */
  63. normalPay = wageRate * hours; /* regular pay rate */
  64. overtimePay = 0; /* no overtime, no overtime pay */
  65. }
  66.  
  67. // Calculate the gross pay with normal pay and any additional overtime pay
  68. grossPay = normalPay + overtimePay;
  69.  
  70. // Print out information on the current employee
  71. // Optional TODO: Feel free to also print out normalPay and overtimePay
  72. printf("\n\nClock# Wage Hours OT Gross\n");
  73. printf("------------------------------------------------\n");
  74. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  75. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0s 5316KB
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