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 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("%-12s %-12s %-10s %-12s %-12s %-12s\n",
  56. "Clock #", "Wage Rate", "Hours", "Normal Pay", "OT Pay", "Gross Pay");
  57. printf("%-12s %-12s %-10s %-12s %-12s %-12s\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("%-12ld $%-11.2f %-10.2f $%-11.2f $%-11.2f $%-11.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.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
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       -33828084913551704064.00 $-358577728231145734144.00 $0.00        $-358577728231145734144.00
526488       $9.75        0.00       $0.00        $0.00        $0.00       
765349       $10.50       0.00       $0.00        $0.00        $0.00       
34645        $12.25       0.00       $0.00        $0.00        $0.00       
127615       $8.35        0.00       $0.00        $0.00        $0.00