fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Name: K. Asha Vigilante-Pini
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  8. //
  9. // Date: 15/06/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. // TODO: Declare and use one more constant
  24. #define OVERTIME_RATE 1.5
  25.  
  26. int main()
  27. {
  28.  
  29. int clockNumber; // Employee clock number
  30. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  31. float hours; // Total hours worked in a week
  32. float normalPay; // Standard weekly normal pay without overtime
  33. float overtimeHrs; // Any hours worked past the normal scheduled work week
  34. float overtimePay; // Additional overtime pay for any overtime hours worked
  35. float wageRate; // Hourly wage for an employee
  36.  
  37. printf ("\n*** Pay Calculator ***");
  38.  
  39. // Process each employee
  40. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  41.  
  42. // Prompt the user for the clock number
  43. printf("\n\nEnter clock number: ");
  44. scanf("%d", &clockNumber);
  45.  
  46. // Prompt the user for the wage rate
  47. printf("\nEnter wage rate: ");
  48. scanf("%f", &wageRate);
  49.  
  50. // Prompt the user for the number of hours worked
  51. printf("\nEnter number of hours worked: ");
  52. scanf("%f", &hours);
  53.  
  54. // Calculate the overtime hours, normal pay, and overtime pay
  55. if (hours > STD_HOURS) {
  56. // TODO: calculate the three values with overtime
  57. overtimeHrs = hours - STD_HOURS;
  58. normalPay = STD_HOURS * wageRate;
  59. overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
  60. } else {
  61. // TODO: calculate the three values without overtime
  62. normalPay = hours * wageRate;
  63. }
  64.  
  65. // Calculate the gross pay with normal pay and any additional overtime pay
  66. grossPay = normalPay + overtimePay;
  67.  
  68. // Print out information on the current employee
  69. // Optional TODO: Feel free to also print out normalPay and overtimePay
  70. printf("\n\nClock# Wage Hours OT Pay OP Gross\n");
  71. printf("------------------------------------------------\n");
  72. printf("%06d %5.2f %5.1f %6.1f %7.2f %8.2f %9.2f\n",
  73. clockNumber, wageRate, hours, overtimeHrs,normalPay, overtimePay, grossPay);
  74. }
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 5312KB
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   Pay   OP    Gross
------------------------------------------------
098401 10.60  51.0   11.0  424.00   174.90    598.90


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

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


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

Clock#  Wage  Hours  OT   Pay   OP    Gross
------------------------------------------------
765349 10.50  37.0    2.5  388.50    36.56    425.06


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

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


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

Clock#  Wage  Hours  OT   Pay   OP    Gross
------------------------------------------------
127615  8.35   0.0    5.0    0.00    91.88     91.88