fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Kamil Kurpiewski
  6. //
  7. // Class: C Programming, Fall, 2025
  8. //
  9. // Date: 9/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. // TODO: Declare and use one more constant
  23. // New Constant
  24. #define SIZE 5
  25.  
  26. // Calculating overtime function
  27. float calculate_overtime_hours(float hours){
  28. if (hours > STD_HOURS) {
  29. return hours - STD_HOURS;
  30. } else {
  31. return 0;
  32. }
  33. }
  34.  
  35. //Gross Pay Function
  36. float calculate_gross_pay(float wage_rate, float hours) {
  37. float normal_pay, overtime_hours, overtime_pay;
  38.  
  39. overtime_hours = calculate_overtime_hours(hours);
  40.  
  41. if (hours > STD_HOURS) {
  42. normal_pay = wage_rate * STD_HOURS;
  43. overtime_pay = overtime_hours * wage_rate * 1.5;
  44.  
  45. } else {
  46. normal_pay = wage_rate * hours;
  47. overtime_pay = 0;
  48. }
  49. return normal_pay + overtime_pay;
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55. int clockNumber; // Employee clock number
  56. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  57. float hours; // Total hours worked in a week
  58. float normalPay; // Standard weekly normal pay without overtime
  59. float overtimeHrs; // Any hours worked past the normal scheduled work week
  60. float overtimePay; // Additional overtime pay for any overtime hours worked
  61. float wageRate; // Hourly wage for an employee
  62.  
  63. printf ("\n*** Pay Calculator ***");
  64.  
  65. // Process each employee
  66. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  67.  
  68. // Prompt the user for the clock number
  69. printf("\n\nEnter clock number: ");
  70. scanf("%d", &clockNumber);
  71.  
  72. // Prompt the user for the wage rate
  73. printf("\nEnter wage rate: ");
  74. scanf("%f", &wageRate);
  75.  
  76. // Prompt the user for the number of hours worked
  77. printf("\nEnter number of hours worked: ");
  78. scanf("%f", &hours);
  79.  
  80. // Using new funtion calculate gross pay
  81. grossPay = calculate_gross_pay(wageRate, hours);
  82.  
  83. //Overtime hours
  84. float overtimeHrs = calculate_overtime_hours(hours);
  85.  
  86. // Print out information on the current employee
  87. printf("\n\nClock# Wage Hours OT Gross\n");
  88. printf("------------------------------------------------\n");
  89. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  90. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  91. }
  92.  
  93. return 0;
  94. }
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  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