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. int main() {
  23. int clockNumber; // Employee clock number
  24. float grossPay; // The weekly gross pay including overtime
  25. float hours; // Total hours worked in a week
  26. float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
  27. float wageRate; // Hourly wage for an employee
  28.  
  29. printf("\n*** Pay Calculator ***");
  30.  
  31. // Process each employee
  32. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  33.  
  34. // Prompt the user for the clock number
  35. printf("\n\nEnter clock number: ");
  36. scanf("%d", &clockNumber);
  37.  
  38. // Prompt the user for the wage rate
  39. printf("\nEnter wage rate: ");
  40. scanf("%f", &wageRate);
  41.  
  42. // Prompt the user for the number of hours worked
  43. printf("\nEnter number of hours worked: ");
  44. scanf("%f", &hours);
  45.  
  46. // Calculate the overtime hours
  47. if (hours > STD_HOURS) {
  48. overtimeHrs = hours - STD_HOURS;
  49. } else {
  50. overtimeHrs = 0.0;
  51. }
  52.  
  53. // Calculate the gross pay with normal pay and any additional overtime pay
  54. if (overtimeHrs > 0) {
  55. grossPay = (STD_HOURS * wageRate) + (overtimeHrs * wageRate * OVERTIME_RATE);
  56. } else {
  57. grossPay = hours * wageRate;
  58. }
  59.  
  60. // Print out information on the current employee
  61. printf("\n\nClock# Wage Hours OT Gross\n");
  62. printf("------------------------------------------------\n");
  63. printf("%06d %7.2f %7.1f %7.1f %9.2f\n",
  64. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  65. }
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5284KB
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