fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Rose Samedi
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 10/4/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 OVERTIME_RATE 1.5
  23. // TODO: Declare and use one more constant
  24.  
  25. int main()
  26. {
  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 counted over 40 a week
  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. // Prompt the user for the wage rate
  45. printf("\nEnter wage rate: ");
  46. scanf("%f", &wageRate);
  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. // TODO: calculate the three new variables with overtime
  59. } else {
  60. // TODO: calculate the three new variables without overtime
  61. }
  62.  
  63. // Calculate the gross pay with normal pay and any additional overtime pay
  64. grossPay = normalPay + overtimePay;
  65.  
  66. // Print out information on the current employee
  67. // Optional TODO: Feel free to also print out normalPay and overtimePay
  68. printf("\n\nClock# Wage Hours OT Gross\n");
  69. printf("------------------------------------------------\n");
  70. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  71. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  72. } // end loop
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 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   0.0     0.00


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
526488  9.75  42.5   0.0     0.00


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

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


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
034645 12.25  45.0   0.0     0.00


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