fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Matt Smith
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: 2/20/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. // hourly pay for each employee
  45. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  46.  
  47. printf ("\n*** Pay Calculator ***\n\n");
  48.  
  49. // Process each employee one at a time
  50. for (i = 0; i < SIZE; i++)
  51. {
  52.  
  53. // TODO - Prompt and Read in hours worked for employee
  54. printf("\nEnter number of hours worked: ");
  55. scanf("%f", &hours[i]);
  56.  
  57. // Calculate overtime and gross pay for employee
  58. if (hours[i] >= STD_HOURS)
  59. {
  60. overtimeHrs[i] = hours[i] - STD_HOURS;
  61. // TODO: Calculate arrays normalPay and overtimePay with overtime
  62. normalPay[i] = STD_HOURS * wageRate[i];
  63. overtimePay[i] = (OT_RATE * wageRate[i]) * overtimeHrs[i];
  64.  
  65. }
  66. else // no OT
  67. {
  68. overtimeHrs[i] = 0;
  69. overtimePay[i] = 0;
  70. // TODO: Calculate arrays normalPay and overtimePay without overtime
  71. normalPay[i] = hours[i] * wageRate[i];
  72.  
  73. }
  74.  
  75. // Calculate Gross Pay
  76. grossPay[i] = normalPay[i] + overtimePay[i];
  77. }
  78.  
  79. // TODO: Print a nice table header
  80.  
  81. // Now that we have all the information in our arrays, we can
  82. // Access each employee and print to screen or file
  83. for (i = 0; i < SIZE; i++)
  84. {
  85. printf("------------------------------------------------\n");
  86. printf("\n\nClock# Wage Hours OT Gross\n");
  87. printf("------------------------------------------------\n");
  88. printf("%06d[i] %5.2f[i] %5.1f[i] %5.1f[i] %8.2f[i]\n",
  89. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  90. // TODO: Print employee information from your arrays
  91.  
  92. }
  93.  
  94. return(0);
  95. }
Success #stdin #stdout 0.01s 5284KB
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[i] 10.60[i]  51.0[i]  11.0[i]   598.90[i]
------------------------------------------------


Clock#  Wage  Hours   OT    Gross
------------------------------------------------
526488[i]  9.75[i]  42.5[i]   2.5[i]   426.56[i]
------------------------------------------------


Clock#  Wage  Hours   OT    Gross
------------------------------------------------
765349[i] 10.50[i]  37.0[i]   0.0[i]   388.50[i]
------------------------------------------------


Clock#  Wage  Hours   OT    Gross
------------------------------------------------
034645[i] 12.25[i]  45.0[i]   5.0[i]   581.88[i]
------------------------------------------------


Clock#  Wage  Hours   OT    Gross
------------------------------------------------
127615[i]  8.35[i]   0.0[i]   0.0[i]     0.00[i]