fork download
  1. //*******************************************************
  2. //
  3. // Homework: 3
  4. //
  5. // Name: Timothy Stockton
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: June 12, 2025
  10. //
  11. // Description: Program which determines overtime and gross pay
  12. // for a set of employees with outputs sent to standard output (the screen).
  13. //
  14. //********************************************************
  15.  
  16. #include <stdio.h>
  17.  
  18. // Declare constants
  19. #define STD_HOURS 40.0 // Hours at normal rate
  20. #define NUM_EMPLOYEES 5 // Number of loop iterations
  21. #define OT_MULTIPLIER 1.5 // Time and a half OT rate
  22.  
  23. int main ( )
  24. {
  25.  
  26. int clockNumber; // Employee clock number
  27. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  28. float hours; // Total hours worked in a week
  29. float normalPay; // Standard weekly normal pay without overtime
  30. float overtimeHrs; // Any hours worked past the normal scheduled work week
  31. float overtimePay; // Additional overtime pay for any overtime hours worked
  32. float wageRate; // Hourly wage for an employee
  33.  
  34. printf ("*** Pay Calculator ***\n");
  35.  
  36. // Process each employee
  37. for (int i = 0; i < NUM_EMPLOYEES; i++)
  38. {
  39. // Prompt the user for the clock number
  40. printf("\nEnter clock number: ");
  41. scanf("%d", &clockNumber);
  42.  
  43. // Prompt the user for the wage rate
  44. printf("\nEnter wage rate: ");
  45. scanf("%f", &wageRate);
  46.  
  47. // Prompt the user for the number of hours worked
  48. printf("\nEnter number of hours worked: ");
  49. scanf("%f", &hours);
  50.  
  51. // Optional TODO: Remove these two statements if desired
  52. // ... were added just for the template to print some values out of the box
  53. grossPay = 0;
  54. overtimeHrs = 0;
  55.  
  56. // Calculate the overtime hours, normal pay, and overtime pay
  57. if (hours > STD_HOURS) {
  58. overtimeHrs = hours - STD_HOURS;
  59. overtimePay = overtimeHrs * (wageRate * OT_MULTIPLIER);
  60. normalPay = STD_HOURS * wageRate;
  61. } else {
  62. overtimeHrs = 0;
  63. overtimePay = 0;
  64. normalPay = hours * wageRate;
  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. } // end for loop
  77.  
  78. return (0); // success
  79.  
  80. } // main
Success #stdin #stdout 0s 5320KB
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