fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Dani D'Oleo Pena
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: 6/18/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.  
  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. //total initialization for optional challenge
  45. float totalWageRate = 0;
  46. float totalHours = 0;
  47. float totalOTHours = 0;
  48. float totalGross = 0;
  49.  
  50. // hourly pay for each employee
  51. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  52.  
  53. printf ("\n*** Pay Calculator ***\n\n");
  54.  
  55. // Process each employee one at a time
  56. for (i = 0; i < SIZE; i++)
  57. {
  58.  
  59. // TODO - Prompt and Read in hours worked for employee
  60. printf("\nEnter number of hours worked: ");
  61. scanf("%f", &hours[i]);
  62.  
  63. // Calculate overtime and gross pay for employee
  64. if (hours[i] >= STD_HOURS)
  65. {
  66. overtimeHrs[i] = hours[i] - STD_HOURS;
  67. // TODO: Calculate arrays normalPay and overtimePay with overtime
  68. normalPay[i] = wageRate[i] * STD_HOURS;
  69. overtimePay[i] = (OT_RATE*wageRate[i])*overtimeHrs[i];
  70. }
  71. else // no OT
  72. {
  73. overtimeHrs[i] = 0;
  74. // TODO: Calculate arrays normalPay and overtimePay without overtime
  75. normalPay[i] = wageRate[i] * hours[i];
  76. overtimePay[i] = 0;
  77.  
  78. }
  79.  
  80. // Calculate Gross Pay
  81. grossPay[i] = normalPay[i] + overtimePay[i];
  82. }
  83.  
  84. // TODO: Print a nice table header
  85. printf("\n\nClock# Wage# Hours OT Gross\n");
  86. printf("------------------------------------------------\n");
  87.  
  88. // Now that we have all the information in our arrays, we can
  89. // Access each employee and print to screen or file
  90. for (i = 0; i < SIZE; i++)
  91. {
  92. // TODO: Print employee information from your arrays
  93. printf("%06ld %5.2f %5.1f %5.1f %8.2f\n",
  94. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  95. totalWageRate += wageRate[i];
  96. totalHours += hours[i];
  97. totalOTHours += overtimeHrs[i];
  98. totalGross += grossPay[i];
  99.  
  100. }
  101. printf("------------------------------------------------\n");
  102. printf("Total\t %5.2f %5.1f %5.1f %8.2f\n",
  103. totalWageRate, totalHours, totalOTHours, totalGross);
  104.  
  105. //Calculate Average
  106. float averageWageRate = totalWageRate/SIZE;
  107. float averageHours = totalHours/SIZE;
  108. float averageOTHours = totalOTHours/SIZE;
  109. float averageGross = totalGross/SIZE;
  110.  
  111. printf("Average\t %5.2f %5.1f %5.1f %8.2f\n",
  112. averageWageRate, averageHours,averageOTHours, averageGross);
  113.  
  114. return(0);
  115. }
Success #stdin #stdout 0.01s 5316KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


Enter number of hours worked: 
Enter number of hours worked: 
Enter number of hours worked: 
Enter number of hours worked: 
Enter number of hours worked: 

Clock# Wage#  Hours  OT      Gross
------------------------------------------------
098401 10.60  51.0  11.0   598.90
526488  9.75  42.5   2.5   426.56
765349 10.50  37.0   0.0   388.50
034645 12.25  45.0   5.0   581.88
127615  8.35   0.0   0.0     0.00
------------------------------------------------
Total	 51.45 175.5  18.5  1995.84
Average	 10.29  35.1   3.7   399.17