fork download
  1. #include <stdio.h>
  2.  
  3. // constants to use
  4. #define SIZE 5 // number of employees to process
  5. #define STD_HOURS 40.0 // normal work week hours before overtime
  6. #define OT_RATE 1.5 // time and half overtime setting
  7.  
  8. int main()
  9. {
  10. // Declare arrays and variables
  11. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // Employee clock numbers
  12. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // Hourly wage rate for each employee
  13. float hours[SIZE]; // Hours worked by each employee in a given week
  14. float normalPay[SIZE]; // Normal weekly pay (no overtime)
  15. float overtimeHrs[SIZE]; // Overtime hours worked in a given week
  16. float overtimePay[SIZE]; // Overtime pay for each employee
  17. float grossPay[SIZE]; // Total gross pay for each employee
  18.  
  19. int i; // Loop variable
  20.  
  21. // Display the program header
  22. printf("\n*** Pay Calculator ***\n\n");
  23.  
  24. // Process each employee
  25. for (i = 0; i < SIZE; i++)
  26. {
  27. // Prompt for hours worked
  28. printf("Enter hours worked for Employee %ld: ", clockNumber[i]);
  29. scanf("%f", &hours[i]);
  30.  
  31. // Calculate overtime hours and pay
  32. if (hours[i] > STD_HOURS)
  33. {
  34. overtimeHrs[i] = hours[i] - STD_HOURS;
  35. normalPay[i] = STD_HOURS * wageRate[i];
  36. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  37. }
  38. else // No overtime
  39. {
  40. overtimeHrs[i] = 0;
  41. normalPay[i] = hours[i] * wageRate[i];
  42. overtimePay[i] = 0;
  43. }
  44.  
  45. // Calculate gross pay (normal pay + overtime pay)
  46. grossPay[i] = normalPay[i] + overtimePay[i];
  47. }
  48.  
  49. // Print the report header
  50. printf("\n--------------------------------------------------------------------------\n");
  51. printf(" Clock# Wage Hours OT Gross\n");
  52. printf("--------------------------------------------------------------------------\n");
  53.  
  54. // Print each employee's data in the formatted table
  55. for (i = 0; i < SIZE; i++)
  56. {
  57. printf("%8ld %5.2f %5.1f %5.1f %8.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5280KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for Employee 98401: Enter hours worked for Employee 526488: Enter hours worked for Employee 765349: Enter hours worked for Employee 34645: Enter hours worked for Employee 127615: 
--------------------------------------------------------------------------
    Clock#   Wage  Hours    OT       Gross
--------------------------------------------------------------------------
   98401   10.60   51.0    11.0     598.90
  526488    9.75   42.5     2.5     426.56
  765349   10.50   37.0     0.0     388.50
   34645   12.25   45.0     5.0     581.88
  127615    8.35    0.0     0.0       0.00