fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Kamil Kurpiewski
  6. //
  7. // Class: C Programming, Fall, 2025
  8. //
  9. // Date: 10/2/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.  
  27.  
  28. // Declare variables needed for the program
  29. // Recommend an array for clock, wage, hours,
  30. // ... and overtime hours and gross.
  31. // Recommend arrays also for normal pay and overtime pay
  32. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  33.  
  34. // unique employee identifier
  35. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  36. float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
  37.  
  38. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  39. float hours [SIZE]; // hours worked in a given week
  40. int i; // loop and array index
  41. float normalPay [SIZE]; // normal weekly pay without any overtime
  42. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  43. float overtimePay [SIZE]; // overtime pay for a given week
  44.  
  45.  
  46. printf ("\n*** Pay Calculator ***\n\n");
  47.  
  48. // Process each employee one at a time
  49. for (i = 0; i < SIZE; i++)
  50. {
  51.  
  52. printf("Enter hours worked for Employee %ld: ", clockNumber[i]);
  53.  
  54. //Read hours user types
  55. scanf("%f", &hours[i]);
  56.  
  57. // Calculate overtime and gross pay for employee
  58. if (hours[i] >= STD_HOURS)
  59. {
  60. overtimeHrs[i] = hours[i] - STD_HOURS;
  61. normalPay[i] = STD_HOURS * wageRate[i];
  62. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  63.  
  64. }
  65. else // no OT
  66. {
  67. overtimeHrs[i] = 0;
  68. normalPay[i] = hours[i] * wageRate[i];
  69. overtimePay[i] = 0;
  70.  
  71. }
  72.  
  73. // Calculate Gross Pay
  74. grossPay[i] = normalPay[i] + overtimePay[i];
  75. }
  76.  
  77. // Table header
  78. printf("\nClock# Wage Hours OT Gross\n");
  79. printf("------------------------------------------------------------\n");
  80.  
  81.  
  82. // Now that we have all the information in our arrays, we can
  83. // Access each employee and print to screen or file
  84. for (i = 0; i < SIZE; i++)
  85. {
  86. printf("%-8ld $%6.2f %6.2f %6.2f $%8.2f\n",
  87. clockNumber[i],
  88. wageRate[i],
  89. hours[i],
  90. overtimeHrs[i],
  91. grossPay[i]);
  92. }
  93.  
  94. return(0);
  95. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
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     Hours     OT     Gross
------------------------------------------------------------
98401     $ 10.60   51.00   11.00  $  598.90
526488    $  9.75   42.50    2.50  $  426.56
765349    $ 10.50   37.00    0.00  $  388.50
34645     $ 12.25   45.00    5.00  $  581.88
127615    $  8.35    0.00    0.00  $    0.00