fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Eiddie Katende
  6. //
  7. // Class: C Programming, Fall 2024
  8. // Date: 9/29/24
  9. // Description: Program which determines overtime and
  10. // gross pay for a set of employees with outputs sent
  11. // to standard output (the screen).
  12. //
  13. //********************************************************
  14.  
  15. #include <stdio.h>
  16.  
  17. // Declare constants
  18. #define STD_HOURS 40.0
  19. #define NUM_EMPLOYEES 5
  20. #define OVERTIME_RATE 1.5
  21.  
  22.  
  23. int main()
  24. {
  25. int clockNumber; // Employee clock number
  26. float grossPay; // The weekly gross pay including overtime
  27. float hours; // Total hours worked in a week
  28. float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
  29. float wageRate; // Hourly wage for an employee
  30.  
  31. printf("\n*** Pay Calculator ***");
  32.  
  33. // Process each employee
  34. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  35.  
  36. // Prompt the user for the clock number
  37. printf("\n\nEnter clock number: ");
  38. scanf ("%d", &clockNumber);
  39.  
  40. // Prompt the user for the wage rate
  41. printf("\nEnter wage rate: ");
  42. scanf ("%f", &wageRate);
  43.  
  44. // Prompt the user for the number of hours worked
  45. printf("\nEnter number of hours worked: ");
  46. scanf ("%f", &hours);
  47.  
  48.  
  49.  
  50. // Calculate the overtime hours
  51. if (hours > STD_HOURS) {
  52. overtimeHrs = hours - STD_HOURS;
  53. }
  54. else {
  55. overtimeHrs = 0.0;
  56. }
  57.  
  58. // Calculate the gross pay with normal pay and any additional overtime pay
  59. if (overtimeHrs > 0) {
  60. grossPay = (STD_HOURS * wageRate) + (overtimeHrs * wageRate * OVERTIME_RATE);
  61. }
  62. else {
  63. grossPay = hours * wageRate;
  64. }
  65. // Print out information on the current employee
  66.  
  67. printf("\n\nClock# Wage Hours OT Gross\n");
  68. printf("------------------------------------------------\n");
  69. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  70. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  71. }
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5292KB
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