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 workweek hours before overtime
  6. #define OT_RATE 1.5 // Overtime rate (1.5 times the regular wage)
  7.  
  8. int main() {
  9. // Declare arrays for employee data
  10. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  11. float grossPay[SIZE]; // Weekly gross pay (normal pay + overtime pay)
  12. float hours[SIZE]; // Hours worked in a given week
  13. int i; // Loop and array index
  14. float normalPay[SIZE]; // Normal weekly pay without any overtime
  15. float overtimeHrs[SIZE]; // Overtime hours worked in a given week
  16. float overtimePay[SIZE]; // Overtime pay for a given week
  17. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // Hourly pay rate for each employee
  18.  
  19. printf("\n*** Pay Calculator ***\n\n");
  20.  
  21. // Process each employee one at a time
  22. for (i = 0; i < SIZE; i++) {
  23. // Prompt and Read in hours worked for each employee
  24. printf("Enter hours worked for employee with clock number %ld: ", clockNumber[i]);
  25. scanf("%f", &hours[i]);
  26.  
  27. // Calculate overtime and gross pay for each employee
  28. if (hours[i] >= STD_HOURS) {
  29. overtimeHrs[i] = hours[i] - STD_HOURS;
  30. normalPay[i] = STD_HOURS * wageRate[i];
  31. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  32. } else { // No overtime
  33. overtimeHrs[i] = 0;
  34. normalPay[i] = hours[i] * wageRate[i];
  35. overtimePay[i] = 0;
  36. }
  37.  
  38. // Calculate Gross Pay
  39. grossPay[i] = normalPay[i] + overtimePay[i];
  40. }
  41.  
  42. // Print a table header
  43. printf("\nClock #\tHours\tNormal Pay\tOvertime Hrs\tOvertime Pay\tGross Pay\n");
  44.  
  45. // Print employee information from the arrays
  46. for (i = 0; i < SIZE; i++) {
  47. printf("%ld\t%.1f\t%.2f\t\t%.1f\t\t%.2f\t\t%.2f\n", clockNumber[i], hours[i], normalPay[i], overtimeHrs[i], overtimePay[i], grossPay[i]);
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***

Enter hours worked for employee with clock number 98401: 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 34645: Enter hours worked for employee with clock number 127615: 
Clock #	Hours	Normal Pay	Overtime Hrs	Overtime Pay	Gross Pay
98401	15995975.0	424.00		15995935.0		254335360.00		254335776.00
526488	0.0	0.00		0.0		0.00		0.00
765349	0.0	0.00		0.0		0.00		0.00
34645	0.0	0.00		0.0		0.00		0.00
127615	0.0	0.00		0.0		0.00		0.00