fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Amanda Connors
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: October 4, 2026
  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.  
  37. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  38. float hours[SIZE]; // hours worked in a given week
  39. int i; // loop and array index
  40. float normalPay[SIZE]; // normal weekly pay without any overtime
  41. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  42. float overtimePay[SIZE]; // overtime pay for a given week
  43.  
  44. float totalWage = 0; // sum of wageRate array calculated later
  45. float totalHrs = 0; // sum of hours array calculated later
  46. float totalOtHrs = 0; // sum of overtimeHrs array calculated later
  47. float totalOtPay = 0; // sum of overtimePay array calculated later
  48. float totalNormPay = 0; // sum of normalPay array calculated later
  49. float totalGross = 0; // sum of grossPay array calculated later
  50.  
  51. // hourly pay for each employee
  52. float wageRate[SIZE] = { 10.6, 9.75, 10.5, 12.25, 8.35 };
  53.  
  54. printf("\n*** Pay Calculator ***\n\n");
  55.  
  56. // Process each employee one at a time
  57. for (i = 0; i < SIZE; i++)
  58. {
  59. // TODO - Prompt and Read in hours worked for employee
  60.  
  61. printf("\n Please enter the number of hours for employee %06li : ", clockNumber[i]);
  62. scanf("%f", &hours[i]);
  63.  
  64.  
  65. // Calculate overtime and gross pay for employee
  66. if (hours[i] >= STD_HOURS)
  67. {
  68. overtimeHrs[i] = hours[i] - STD_HOURS;
  69. // TODO: Calculate arrays normalPay and overtimePay with overtime
  70.  
  71. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  72. normalPay[i] = STD_HOURS * wageRate[i];
  73.  
  74. } //end if
  75. else // no OT
  76. {
  77. overtimeHrs[i] = 0;
  78. // TODO: Calculate arrays normalPay and overtimePay without overtime
  79. overtimePay[i] = 0;
  80. normalPay[i] = hours[i] * wageRate[i];
  81.  
  82. } // end else
  83.  
  84. // Calculate Gross Pay
  85. grossPay[i] = normalPay[i] + overtimePay[i];
  86. } // end for
  87.  
  88. // TODO: Print a nice table header
  89. printf("\n\n------------------------------------------------------------------\n");
  90. printf(" Clock#\t Wage\t Hours\t OT \tStandard Pay\tOT Pay\t Gross");
  91. printf("\n------------------------------------------------------------------\n");
  92. // Now that we have all the information in our arrays, we can
  93. // Access each employee and print to screen or file
  94. for (i = 0; i < SIZE; i++)
  95. {
  96. // TODO: Print employee information from your arrays
  97. printf(" %06li\t %5.2f\t %5.1f\t %5.1f\t %8.2f\t %8.2f\t %8.2f\n",
  98. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], normalPay[i], overtimePay[i], grossPay[i]);
  99. } //end for
  100.  
  101. // calculate the sum total of arrays
  102. for (i = 0; i < SIZE; i++)
  103. {
  104. totalWage += wageRate[i];
  105. totalHrs += hours[i];
  106. totalOtHrs += overtimeHrs[i];
  107. totalOtPay += overtimePay[i];
  108. totalNormPay += normalPay[i];
  109. totalGross += grossPay[i];
  110.  
  111. } //end for
  112.  
  113. // calculate averages
  114. float payAvg = totalWage / SIZE;
  115. float hoursAvg = totalHrs / SIZE;
  116. float otHrsAvg = totalOtHrs / SIZE;
  117. float normPayAvg = totalNormPay / SIZE;
  118. float otPayAvg = totalOtPay / SIZE;
  119. float grossAvg = totalGross / SIZE;
  120.  
  121. // print the totals and averages
  122. printf(" ------\t -----\t ----- \t-------\t --------\t -------\t --------\n");
  123.  
  124. printf(" Total\t %5.2f\t %5.1f\t %5.1f\t %8.2f\t %8.2f\t %8.2f\n",
  125. totalWage, totalHrs, totalOtHrs, totalNormPay, totalOtPay, totalGross);
  126.  
  127. printf(" Average %5.2f\t %5.1f\t %5.1f\t %8.2f\t %8.2f\t %8.2f\n",
  128. payAvg, hoursAvg, otHrsAvg, normPayAvg, otPayAvg, grossAvg);
  129.  
  130.  
  131.  
  132. return(0);
  133. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


 Please enter the number of hours for employee 098401 : 
 Please enter the number of hours for employee 526488 : 
 Please enter the number of hours for employee 765349 : 
 Please enter the number of hours for employee 034645 : 
 Please enter the number of hours for employee 127615 : 

------------------------------------------------------------------
 Clock#	 Wage	 Hours	  OT 	Standard Pay	OT Pay	   Gross
------------------------------------------------------------------
 098401	 10.60	  51.0	  11.0	   424.00	   174.90	   598.90
 526488	  9.75	  42.5	   2.5	   390.00	    36.56	   426.56
 765349	 10.50	  37.0	   0.0	   388.50	     0.00	   388.50
 034645	 12.25	  45.0	   5.0	   490.00	    91.88	   581.88
 127615	  8.35	   0.0	   0.0	     0.00	     0.00	     0.00
 ------	 -----	 ----- 	-------	 --------	   -------	 --------
 Total	 51.45	 175.5	  18.5	  1692.50	   303.34	  1995.84
 Average 10.29	  35.1	   3.7	   338.50	    60.67	   399.17