fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: Fisher Brown
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: February 16, 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 OT_RATE 1.5 // Overtime pay multiplier
  23.  
  24. int main()
  25. {
  26. int clockNumber; // Employee clock number
  27. float wageRate; // Hourly wage for an employee
  28. float hours; // Total hours worked in a week
  29. float normalPay; // Standard weekly normal pay (without overtime)
  30. float overtimeHrs; // Overtime hours worked beyond 40
  31. float overtimePay; // Overtime pay amount
  32. float grossPay; // Total weekly gross pay (normal + overtime)
  33.  
  34. printf("\n*** Pay Calculator ***\n");
  35.  
  36. // Process each employee
  37. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  38.  
  39. // Prompt the user for input
  40. printf("\nEnter clock number: ");
  41. scanf("%d", &clockNumber);
  42.  
  43. printf("Enter wage rate: ");
  44. scanf("%f", &wageRate);
  45.  
  46. printf("Enter number of hours worked: ");
  47. scanf("%f", &hours);
  48.  
  49. // Initialize variables
  50. overtimeHrs = 0;
  51. overtimePay = 0;
  52. normalPay = wageRate * hours;
  53.  
  54. // Calculate overtime if hours exceed 40
  55. if (hours > STD_HOURS) {
  56. overtimeHrs = hours - STD_HOURS;
  57. overtimePay = (wageRate * OT_RATE) * overtimeHrs;
  58. normalPay = wageRate * STD_HOURS; // Cap normal pay at 40 hours
  59. }
  60.  
  61. // Calculate total gross pay
  62. grossPay = normalPay + overtimePay;
  63.  
  64. // Print the employee's payroll information
  65. printf("\n------------------------------------------------");
  66. printf("\nClock# Wage Hours OT Gross");
  67. printf("\n------------------------------------------------");
  68. printf("\n%06d %5.2f %5.1f %5.1f %8.2f\n",
  69. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  70. }
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 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