fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Thomas Scappaticci
  6. //
  7. // Class: C Programming, Spring 2024
  8. //
  9. // Date: 2/18/2024
  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
  20. #define SIZE 5 // Number of Employees to process
  21. #define STD_HOURS 40.0 // Standard Work Hours per week
  22. #define OT_PAY 1.5 // ADDED: Pay rate for OT
  23.  
  24. int main ()
  25. {
  26.  
  27. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615}; // Array for Employee ID
  28.  
  29. float grossPay [SIZE]; // weekly gross pay which is normalPay + overtimePay
  30. float hours [SIZE]; // number of hours worked per week
  31. float normalPay [SIZE]; // Standard pay per week without overtime
  32. float overtimeHrs [SIZE]; // number of hours worked per week
  33. float overtimePay [SIZE]; // additional pay for overtime hours worked
  34. int i; // Loop and Array INDEX
  35.  
  36. float TotalwageRate; // Sum of all wage rates
  37. float Totalhours; // Sum of all hours worked
  38. float TotalovertimeHrs; // Sum of all overtime hours worked
  39. float TotalgrossPay; // Sum of all gross payment
  40.  
  41. float AVGwageRate; // Average of all wage rates
  42. float AVGhours; // Average of all hours worked
  43. float AVGovertimeHrs; // Average of all overtime hours worked
  44. float AVGgrossPay; // Average of all gross payment
  45.  
  46.  
  47. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // Hourly Wage per Employee
  48.  
  49. // Header Print
  50. printf ("\n\t*** Pay Calculator ***\n");
  51.  
  52. // Process each employee's hours worked and calculate pay and overtime
  53.  
  54. for (int i = 0; i < SIZE; i++ )
  55. {
  56.  
  57. // Prompt the user for the number of hours worked
  58. printf ("\nEnter the number of hours worked for Employee %d: \n", clockNumber[i]);
  59. scanf ("%f", &hours[i]);
  60.  
  61. // calculate overtime hours, normal pay, and overtime pay
  62.  
  63. // *IF* Statement if hours exceed standard hours
  64.  
  65. if (hours[i] > STD_HOURS)
  66. {
  67. overtimeHrs[i] = hours[i] - STD_HOURS; // Overtime = Dif between hours worked and standard hours
  68. normalPay[i] = wageRate[i] * STD_HOURS; // Normal pay = Wages * std hours
  69. overtimePay[i] = (wageRate[i] * OT_PAY) * overtimeHrs[i]; // overtime = wages * OT_PAY * overtime hours
  70.  
  71. } //if
  72.  
  73. // *ELSE* Statement if hours do not exceed standard hours
  74.  
  75. else{
  76. overtimeHrs[i] = 0; // No overtime worked
  77. normalPay[i] = wageRate[i] * hours[i]; // Normal pay = Wages * std hours
  78. overtimePay[i] = 0; // No overtime pay
  79.  
  80. } // else
  81.  
  82. // calculate gross pay with normal and overtime pay
  83.  
  84. grossPay[i] = normalPay[i] + overtimePay[i];
  85.  
  86. } // for
  87.  
  88. // Header for Employee Info Table
  89. printf ("\n\n\t----------------------------------------------------------\n");
  90. printf ("\t\t\tClock # Wage Hours OT Gross\n");
  91. printf ("\t----------------------------------------------------------\n");
  92.  
  93. // Print array info for each employee
  94.  
  95. for (int i = 0; i < SIZE; i++ )
  96. {
  97.  
  98. printf("\t\t\t%06d %5.2f %5.1f %5.1f %8.2f\n",
  99. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  100.  
  101. } // for
  102.  
  103. // Calculate Total and Average Values
  104.  
  105. for (int i = 0; i < SIZE; i++ )
  106. {
  107.  
  108. TotalwageRate = TotalwageRate + wageRate[i];
  109. Totalhours = Totalhours + hours[i];
  110. TotalovertimeHrs = TotalovertimeHrs + overtimeHrs[i];
  111. TotalgrossPay = TotalgrossPay + grossPay[i];
  112.  
  113. AVGwageRate = TotalwageRate / SIZE;
  114. AVGhours = Totalhours / SIZE;
  115. AVGovertimeHrs = TotalovertimeHrs / SIZE;
  116. AVGgrossPay = TotalgrossPay / SIZE;
  117.  
  118. }
  119.  
  120. // Print out Total Values and Average Values
  121.  
  122. printf ("\n\n\t----------------------------------------------------------\n");
  123.  
  124. printf ("\tTotal");
  125. printf("\t\t%5.2f %5.1f %5.1f %8.2f\n",
  126. TotalwageRate, Totalhours, TotalovertimeHrs, TotalgrossPay);
  127.  
  128. printf ("\tAverage");
  129. printf("\t\t%5.2f %5.1f %5.1f %8.2f\n",
  130. AVGwageRate, AVGhours, AVGovertimeHrs, AVGgrossPay);
  131.  
  132. // Bottom Print
  133. printf("\n\n\tThank you for using employee calculator!");
  134.  
  135. return (0); // success
  136.  
  137. } // main
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
	*** Pay Calculator ***

Enter the number of hours worked for Employee 98401: 

Enter the number of hours worked for Employee 526488: 

Enter the number of hours worked for Employee 765349: 

Enter the number of hours worked for Employee 34645: 

Enter the number of hours worked for Employee 127615: 


	----------------------------------------------------------
			Clock # Wage  Hours  OT   Gross
	----------------------------------------------------------
			098401 10.60 6304.4 6264.4 100027.20
			526488  9.75   0.0   0.0     0.00
			765349 10.50  -0.0   0.0    -0.04
			034645 12.25   0.0   0.0     0.00
			127615  8.35   0.0   0.0     0.00


	----------------------------------------------------------
	Total		51.45 6304.3 6264.4 100027.16
	Average		10.29 1260.9 1252.9 20005.43


	Thank you for using employee calculator!