fork(1) 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 variables needed for the program
  11. // unique employee identifier
  12. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  13.  
  14. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  15. float hours [SIZE]; // hours worked in a given week
  16. int i; // loop and array index
  17. float normalPay [SIZE]; // normal weekly pay without any overtime
  18. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  19. float overtimePay [SIZE]; // overtime pay for a given week
  20.  
  21. // hourly pay for each employee
  22. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  23.  
  24. printf ("\n*** Pay Calculator ***\n\n");
  25.  
  26. // Process each employee one at a time
  27. for (i = 0; i < SIZE; i++)
  28. {
  29. // Prompt and Read in hours worked for employee
  30. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  31. scanf("%f", &hours[i]);
  32.  
  33. // Calculate overtime and gross pay for employee
  34. if (hours[i] >= STD_HOURS)
  35. {
  36. overtimeHrs[i] = hours[i] - STD_HOURS;
  37. // Calculate arrays normalPay and overtimePay with overtime
  38. normalPay[i] = STD_HOURS * wageRate[i];
  39. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  40. }
  41. else // no OT
  42. {
  43. overtimeHrs[i] = 0;
  44. // Calculate arrays normalPay and overtimePay without overtime
  45. normalPay[i] = hours[i] * wageRate[i];
  46. overtimePay[i] = 0;
  47. }
  48.  
  49. // Calculate Gross Pay
  50. grossPay[i] = normalPay[i] + overtimePay[i];
  51. }
  52.  
  53. // Print a nice table header
  54. printf("\n\n");
  55. printf("%5s %5s %5s %5s %5s %5s\n",
  56. "Clock #", "Wage Rate", "Hours", "Normal Pay", "OT Pay", "Gross Pay");
  57. printf("%5s %5s %5s %5s %5s %5s\n",
  58. "--------", "---------", "-----", "-----------", "-------", "---------");
  59.  
  60. // Now that we have all the information in our arrays, we can
  61. // Access each employee and print to screen or file
  62. for (i = 0; i < SIZE; i++)
  63. {
  64. // Print employee information from your arrays
  65. printf("%-5ld $%-5.2f %-5.2f $%-5.2f $%-5.2f $%-5.2f\n",
  66. clockNumber[i], wageRate[i], hours[i],
  67. normalPay[i], overtimePay[i], grossPay[i]);
  68. }
  69.  
  70. printf("\n");
  71. return(0);
  72. }
  73.  
  74.  
Success #stdin #stdout 0s 5316KB
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 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 Rate Hours Normal Pay OT Pay Gross Pay
-------- --------- ----- ----------- ------- ---------
98401 $10.60 98401.00 $424.00 $1563940.00 $1564364.00
526488 $9.75  10.60 $103.35 $0.00  $103.35
765349 $10.50 51.00 $420.00 $173.25 $593.25
34645 $12.25 526488.00 $490.00 $9673482.00 $9673972.00
127615 $8.35  9.75  $81.41 $0.00  $81.41