fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Joy Akoso>
  6. //
  7. // Class: C Programming, <Fall 2025>
  8. //
  9. // Date: <10/3/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.  
  18. #include <stdio.h>
  19.  
  20. // constants to use
  21. #define SIZE 5 // number of employees to process
  22. #define STD_HOURS 40.0 // normal work week hours before overtime
  23. #define OT_RATE 1.5 // time and half overtime setting
  24.  
  25. int main()
  26. {
  27. // unique employee identifier
  28. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  29.  
  30. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  31. float hours [SIZE]; // hours worked in a given week
  32. int i; // loop and array index
  33. float normalPay [SIZE]; // normal weekly pay without any overtime
  34. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  35. float overtimePay [SIZE]; // overtime pay for a given week
  36.  
  37. // hourly pay for each employee
  38. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  39.  
  40. printf ("\n*** Pay Calculator ***\n\n");
  41.  
  42. // Process each employee one at a time
  43. for (i = 0; i < SIZE; i++)
  44. {
  45. // Prompt and Read in hours worked for employee
  46. printf("Enter hours worked for employee with clock number %06ld: ", clockNumber[i]);
  47. scanf("%f", &hours[i]);
  48.  
  49. // Calculate overtime and gross pay for employee
  50. if (hours[i] > STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS;
  53.  
  54. //Calculating arrays for normalPay and overtimePay with overtime
  55. normalPay[i] = STD_HOURS * wageRate[i];
  56. overtimePay[i] = overtimeHrs[i] * (OT_RATE * wageRate[i]);
  57. }
  58. else // no OT
  59. {
  60. overtimeHrs[i] = 0;
  61.  
  62. //Calculating arrays for normalPay and overtimePay without overtime
  63. normalPay[i] = hours[i] * wageRate[i];
  64. overtimePay[i] = 0;
  65. }
  66.  
  67. // Calculate Gross Pay
  68. grossPay[i] = normalPay[i] + overtimePay[i];
  69. }
  70.  
  71. // This Prints a nice table header
  72. printf("\n\n-------------------------------------------------------------\n");
  73. printf("Clock# Wage Hours OT Hours OT Pay Gross\n");
  74. printf("-------------------------------------------------------------\n");
  75.  
  76. // Now that we have all the information in our arrays, we can
  77. // Access each employee and print to screen or file
  78. for (i = 0; i < SIZE; i++)
  79. {
  80. // This Prints employee information from my arrays
  81. printf("%06ld %6.2f %6.1f %8.1f %8.2f %8.2f\n",
  82. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i],
  83. overtimePay[i], grossPay[i]);
  84. }
  85.  
  86. return(0);
  87. }
  88.  
Success #stdin #stdout 0.01s 5316KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee with clock number 098401: Enter hours worked for employee with clock number 526488: Enter hours worked for employee with clock number 765349: Enter hours worked for employee with clock number 034645: Enter hours worked for employee with clock number 127615: 

-------------------------------------------------------------
Clock#    Wage   Hours   OT Hours   OT Pay     Gross
-------------------------------------------------------------
098401   10.60    51.0      11.0    174.90   598.90
526488    9.75    42.5       2.5     36.56   426.56
765349   10.50    37.0       0.0      0.00   388.50
034645   12.25    45.0       5.0     91.88   581.88
127615    8.35     0.0       0.0      0.00     0.00