fork(2) download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Larson Klipic
  6. //
  7. // Class: C Programming, summer 26
  8. //
  9. // Date: JUN 20th
  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. // unique employee identifier
  27. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  28.  
  29. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  30. float hours[SIZE]; // hours worked in a given week
  31. int i; // loop and array index
  32. float normalPay[SIZE]; // normal weekly pay without any overtime
  33. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  34. float overtimePay[SIZE]; // overtime pay for a given week
  35.  
  36. // hourly pay for each employee
  37. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  38.  
  39. printf("\n*** Pay Calculator ***\n\n");
  40.  
  41. // Process each employee one at a time
  42. for (i = 0; i < SIZE; i++)
  43. {
  44. // FIXED: Changed %lf to %f to match float array, and added missing '&'
  45. printf("Enter hours worked for employee %06li: ", 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] = wageRate[i] * STD_HOURS;
  53. // FIXED: Overtime rate must be multiplied by the employee's wage rate
  54. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  55. }
  56. else // no OT
  57. {
  58. overtimeHrs[i] = 0;
  59. overtimePay[i] = 0;
  60. normalPay[i] = wageRate[i] * hours[i];
  61. }
  62.  
  63. // Calculate Gross Pay
  64. grossPay[i] = normalPay[i] + overtimePay[i];
  65. }
  66.  
  67. // Table Header
  68. // Spacing formatted to perfectly align with the print statement below
  69. printf("\n\nClock# Wage Hours Reg-Pay OT-Hrs OT-Pay Gross\n");
  70. printf("-----------------------------------------------------------------\n");
  71.  
  72. // FIXED: Print out all calculated metrics for each employee line by line
  73. for (i = 0; i < SIZE; i++)
  74. {
  75. printf("%06li %5.2f %5.1f %7.2f %6.1f %6.2f %7.2f\n",
  76. clockNumber[i], wageRate[i], hours[i], normalPay[i],
  77. overtimeHrs[i], overtimePay[i], grossPay[i]);
  78. }
  79.  
  80. return(0);
  81. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee 098401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 034645: Enter hours worked for employee 127615: 

Clock#   Wage   Hours   Reg-Pay   OT-Hrs   OT-Pay   Gross
-----------------------------------------------------------------
098401   10.60    51.0    424.00     11.0   174.90    598.90
526488    9.75    42.5    390.00      2.5    36.56    426.56
765349   10.50    37.0    388.50      0.0     0.00    388.50
034645   12.25    45.0    490.00      5.0    91.88    581.88
127615    8.35     0.0      0.00      0.0     0.00      0.00