fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <replace with your name>
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  8. //
  9. // Date: <replace with the current date>
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. //********************************************************
  16.  
  17. #include <stdio.h>
  18.  
  19. // constants to use
  20. #define SIZE 5 // number of employees to process
  21. #define STD_HOURS 40.0 // normal work week hours before overtime
  22. #define OT_RATE 1.5 // time and half overtime setting
  23.  
  24. int main()
  25. {
  26. // Declare variables needed for the program
  27.  
  28. // unique employee identifier
  29. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  30.  
  31. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  32. float hours[SIZE]; // hours worked in a given week
  33. float normalPay[SIZE]; // normal weekly pay without any overtime
  34. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  35. float overtimePay[SIZE]; // overtime pay for a given week
  36. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // hourly pay
  37.  
  38. int i; // loop and array index
  39.  
  40. printf("\n*** Pay Calculator ***\n\n");
  41.  
  42. // Process each employee one at a time
  43. for (i = 0; i < SIZE; i++)
  44. {
  45. printf("Enter hours worked for employee #%ld: ", clockNumber[i]);
  46. scanf("%f", &hours[i]);
  47.  
  48. // Calculate overtime and gross pay for employee
  49. if (hours[i] > STD_HOURS)
  50. {
  51. overtimeHrs[i] = hours[i] - STD_HOURS;
  52. normalPay[i] = STD_HOURS * wageRate[i];
  53. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  54. }
  55. else // no OT
  56. {
  57. overtimeHrs[i] = 0;
  58. normalPay[i] = hours[i] * wageRate[i];
  59. overtimePay[i] = 0;
  60. }
  61.  
  62. // Calculate Gross Pay
  63. grossPay[i] = normalPay[i] + overtimePay[i];
  64. }
  65.  
  66. // Print table header
  67. printf("\n------------------------------------------------------------\n");
  68. printf("Clock# Wage Hours OT Hrs Normal Pay OT Pay Gross\n");
  69. printf("------------------------------------------------------------\n");
  70.  
  71. // Print employee information
  72. for (i = 0; i < SIZE; i++)
  73. {
  74. printf("%06ld %6.2f %6.2f %6.2f %10.2f %7.2f %7.2f\n",
  75. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i],
  76. normalPay[i], overtimePay[i], grossPay[i]);
  77. }
  78.  
  79. printf("------------------------------------------------------------\n");
  80.  
  81. return(0);
  82. }
  83.  
Success #stdin #stdout 0.01s 5316KB
stdin
51.0
42.5
37.0
45.0
33
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 Hrs   Normal Pay   OT Pay   Gross
------------------------------------------------------------
098401   10.60   51.00   11.00       424.00   174.90   598.90
526488    9.75   42.50    2.50       390.00    36.56   426.56
765349   10.50   37.00    0.00       388.50     0.00   388.50
034645   12.25   45.00    5.00       490.00    91.88   581.88
127615    8.35   33.00    0.00       275.55     0.00   275.55
------------------------------------------------------------