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 a half overtime setting
  7.  
  8. int main()
  9. {
  10. // Declare arrays for employee data
  11. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  12. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  13. float hours[SIZE]; // Hours worked in a given week
  14. float overtimeHrs[SIZE]; // Overtime hours worked
  15. float normalPay[SIZE]; // Pay for standard hours
  16. float overtimePay[SIZE]; // Overtime pay
  17. float grossPay[SIZE]; // Total gross pay
  18.  
  19. int i; // Loop index
  20.  
  21. printf("\n*** Pay Calculator ***\n\n");
  22.  
  23. // Prompt and read in hours worked for each employee
  24. for (i = 0; i < SIZE; i++) {
  25. printf("Enter hours worked for employee with clock number %06ld: ", clockNumber[i]);
  26. scanf("%f", &hours[i]);
  27. }
  28.  
  29. // Calculate pay for each employee
  30. for (i = 0; i < SIZE; i++) {
  31. if (hours[i] > STD_HOURS) {
  32. overtimeHrs[i] = hours[i] - STD_HOURS;
  33. normalPay[i] = wageRate[i] * STD_HOURS;
  34. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  35. } else {
  36. overtimeHrs[i] = 0.0;
  37. normalPay[i] = wageRate[i] * hours[i];
  38. overtimePay[i] = 0.0;
  39. }
  40.  
  41. grossPay[i] = normalPay[i] + overtimePay[i];
  42. }
  43.  
  44. // Print a table header
  45. printf("\n--------------------------------------------------------------\n");
  46. printf(" Clock# Wage Hours OT Gross\n");
  47. printf("--------------------------------------------------------------\n");
  48.  
  49. // Print employee pay information
  50. for (i = 0; i < SIZE; i++) {
  51. printf(" %06ld %5.2f %5.1f %5.1f %8.2f\n",
  52. clockNumber[i],
  53. wageRate[i],
  54. hours[i],
  55. overtimeHrs[i],
  56. grossPay[i]);
  57. }
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5312KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee with clock number 098401: Enter hours worked for employee with clock number 526488: Enter hours worked for employee with clock number 765349: Enter hours worked for employee with clock number 034645: Enter hours worked for employee with clock number 127615: 
--------------------------------------------------------------
  Clock#   Wage   Hours    OT     Gross
--------------------------------------------------------------
 098401   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
 034645   12.25    45.0     5.0     581.88
 127615    8.35     0.0     0.0       0.00