fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Mary Paul>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <February 19, 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. // hourly pay for each employee
  45. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  46. float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
  47.  
  48. printf ("\n*** Pay Calculator ***\n\n");
  49.  
  50. // Process each employee one at a time
  51. for (i = 0; i < SIZE; i++)
  52. {
  53. printf("Enter hours worked for clock %ld: ", clockNumber[i]);
  54. scanf("%f", &hours[i]);
  55.  
  56. // TODO - Prompt and Read in hours worked for employee
  57.  
  58. // Calculate overtime and gross pay for employee
  59. if (hours[i] > STD_HOURS)
  60. {
  61. overtimeHrs[i] = hours[i] - STD_HOURS;
  62. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  63. normalPay[i] = STD_HOURS * wageRate[i];
  64.  
  65. // TODO: Calculate arrays normalPay and overtimePay with overtime
  66.  
  67. }
  68. else // no OT
  69. {
  70. overtimeHrs[i] = 0;
  71. overtimePay[i] = 0;
  72. normalPay[i] = hours[i] * wageRate[i];
  73.  
  74. // TODO: Calculate arrays normalPay and overtimePay without overtime
  75.  
  76. }
  77.  
  78. // Calculate Gross Pay
  79. grossPay[i] = normalPay[i] + overtimePay[i];
  80. totalWage += wageRate[i];
  81. totalHours += hours[i];
  82. totalOT += overtimeHrs[i];
  83. totalGross += grossPay[i];
  84. }
  85.  
  86.  
  87. printf("\nClock# Wage Hours OT Gross\n");
  88. printf("---------------------------------------------------------\n");
  89.  
  90. // TODO: Print a nice table header
  91.  
  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. printf("%06ld %.2f %.2f %.2f %.2f\n",
  97. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  98.  
  99. // TODO: Print employee information from your arrays
  100. }
  101.  
  102. printf("---------------------------------------------------------\n");
  103. printf("Total: %.2f %.2f %.2f %.2f\n",
  104. totalWage, totalHours, totalOT, totalGross);
  105. printf("Average: %.2f %.2f %.2f %.2f\n",
  106. totalWage/SIZE, totalHours/SIZE, totalOT/SIZE, totalGross/SIZE);
  107.  
  108. return(0);
  109. }
Success #stdin #stdout 0s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for clock 98401: Enter hours worked for clock 526488: Enter hours worked for clock 765349: Enter hours worked for clock 34645: Enter hours worked for clock 127615: 
Clock#		Wage	 Hours	  OT	  Gross
---------------------------------------------------------
098401		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
034645		12.25   45.00 5.00 581.88
127615		8.35   0.00 0.00 0.00
---------------------------------------------------------
Total:	51.45 175.50 18.50 1995.84
Average:  10.29 35.10 3.70  399.17