fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: <Joy Akoso>
  6. //
  7. // Class: C Programming, <Fall 2025>
  8. //
  9. // Date: <09/26/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.  
  23. // Declaring a new constant called OverTime_RATE, and setting its value to 2.5
  24. #define OverTime_RATE 2.5 // Overtime is paid at 2.5x the normal wage
  25.  
  26. int main()
  27. {
  28. int clockNumber; // Employee clock number
  29. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  30. float hours; // Total hours worked in a week
  31. float normalPay; // Standard weekly normal pay without overtime
  32. float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
  33. float overtimePay; // Any hours worked past the normal scheduled work week
  34. float wageRate; // Hourly wage for an employee
  35.  
  36. printf ("\n*** Pay Calculator ***");
  37.  
  38. // Process each employee
  39. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  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. // Calculating the overtime hours, normal pay, and overtime pay
  54. if (hours > STD_HOURS)
  55. {
  56. //calculating the three values with overtime, this is where we use the new constant we declared above
  57. //... which was OverTime_RATE
  58. overtimeHrs = hours - STD_HOURS;
  59. normalPay = STD_HOURS * wageRate;
  60. overtimePay = overtimeHrs * (OverTime_RATE * wageRate);
  61. }
  62. else {
  63. //calculating the three values without overtime
  64. overtimeHrs = 0;
  65. normalPay = hours * wageRate;
  66. overtimePay = 0;
  67. }
  68.  
  69. // Calculate the gross pay with normal pay and any additional overtime pay
  70. grossPay = normalPay + overtimePay;
  71.  
  72. // Print out information on the current employee
  73. printf("\n\nClock# Wage Hours OverTime Gross\n");
  74. printf("------------------------------------------------\n");
  75. printf("%06d %7.2f %6.1f %5.1f %9.2f\n",
  76. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  77. }
  78.  
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0s 5276KB
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   OverTime   Gross
------------------------------------------------
098401   10.60   51.0  11.0    715.50


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

Clock#   Wage   Hours   OverTime   Gross
------------------------------------------------
526488    9.75   42.5   2.5    450.94


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

Clock#   Wage   Hours   OverTime   Gross
------------------------------------------------
765349   10.50   37.0   0.0    388.50


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

Clock#   Wage   Hours   OverTime   Gross
------------------------------------------------
034645   12.25   45.0   5.0    643.12


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

Clock#   Wage   Hours   OverTime   Gross
------------------------------------------------
127615    8.35    0.0   0.0      0.00