fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Anthony Principe
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: September 28th 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 OT_RATE 1.5 // Overtime multiplier
  23.  
  24. int main()
  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 ("\n*** Pay Calculator ***");
  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("\n\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. // Calculate the overtime hours, normal pay, and overtime pay
  52. if (hours > STD_HOURS) {
  53. overtimeHrs = hours - STD_HOURS;
  54. normalPay = STD_HOURS * wageRate;
  55. overtimePay = overtimeHrs * wageRate * OT_RATE;
  56. } else {
  57. overtimeHrs = 0;
  58. normalPay = hours * wageRate;
  59. overtimePay = 0;
  60. }
  61.  
  62. // Calculate the gross pay with normal pay and any additional overtime pay
  63. grossPay = normalPay + overtimePay;
  64.  
  65. // Print out information on the current employee
  66. printf("\n\nClock# Wage Hours OT Hrs OT Pay Gross\n");
  67. printf("-------------------------------------------------------\n");
  68. printf("%06d %7.2f %7.1f %7.1f %8.2f %8.2f\n",
  69. clockNumber, wageRate, hours, overtimeHrs, overtimePay, grossPay);
  70. }//for
  71.  
  72. return 0;
  73. }//main
  74.  
Success #stdin #stdout 0.01s 5308KB
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 Hrs   OT Pay   Gross
-------------------------------------------------------
098401   10.60    51.0    11.0   174.90   598.90


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

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


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

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


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

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


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

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