fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Kyle Merrihew>
  6. //
  7. // Class: C Programming, <Spring 2025>
  8. //
  9. // Date: <February 20, 2025>
  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. // Prompt and Read in hours worked for employee
  45. printf("Enter hours worked for employee with clock number %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. // Calculate normal pay and overtime pay with overtime
  53. normalPay[i] = STD_HOURS * wageRate[i];
  54. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  55. }
  56. else // no OT
  57. {
  58. overtimeHrs[i] = 0;
  59. // Calculate normal pay and overtime pay without overtime
  60. normalPay[i] = hours[i] * wageRate[i];
  61. overtimePay[i] = 0;
  62. }
  63.  
  64. // Calculate Gross Pay
  65. grossPay[i] = normalPay[i] + overtimePay[i];
  66. }
  67.  
  68. // Print a nice table header
  69. printf("\nEmployee Pay Report\n");
  70. printf("-------------------------------------------------------------\n");
  71. printf("Clock Number | Hours Worked | Normal Pay | Overtime Pay | Gross Pay\n");
  72. printf("-------------------------------------------------------------\n");
  73.  
  74. // Now that we have all the information in our arrays, we can
  75. // Access each employee and print to screen
  76. for (i = 0; i < SIZE; i++)
  77. {
  78. printf("%ld\t\t", clockNumber[i]);
  79. printf("%.2f\t\t", hours[i]);
  80. printf("%.2f\t\t", normalPay[i]);
  81. printf("%.2f\t\t", overtimePay[i]);
  82. printf("%.2f\n", grossPay[i]);
  83. }
  84.  
  85. return(0);
  86. }
Success #stdin #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
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: 
Employee Pay Report
-------------------------------------------------------------
Clock Number | Hours Worked | Normal Pay | Overtime Pay | Gross Pay
-------------------------------------------------------------
98401		51.00		424.00		174.90		598.90
526488		42.50		390.00		36.56		426.56
765349		37.00		388.50		0.00		388.50
34645		45.00		490.00		91.88		581.88
127615		0.00		0.00		0.00		0.00