fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Timothy Stockton
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: June 20th, 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
  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. // Declare variables needed for the program
  28.  
  29. // unique employee identifier
  30. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  31.  
  32. float grossPay [SIZE]; // weekly gross pay: normal pay + overtime pay
  33. float hours [SIZE]; // total hours worked in a given week
  34. int i; // loop and array index
  35. float normalPay [SIZE]; // normal weekly pay without any overtime
  36. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  37. float overtimePay [SIZE]; // overtime pay for a given week
  38.  
  39. // hourly pay for each employee
  40. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  41.  
  42. printf ("\n*** Pay Calculator ***\n");
  43.  
  44. // Process each employee one at a time
  45. for (i = 0; i < SIZE; i++)
  46. {
  47. // Prompt the user for the number of hours worked
  48. printf("\nEnter number of hours worked: ");
  49. scanf("%f", &hours[i]);
  50.  
  51. // Calculate overtime and normal pay for employee
  52. if (hours[i] > STD_HOURS)
  53. {
  54. overtimeHrs[i] = hours[i] - STD_HOURS;
  55. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  56. normalPay[i] = STD_HOURS * wageRate[i];
  57. }
  58. else // no OT
  59. {
  60. overtimeHrs[i] = 0;
  61. overtimePay[i] = 0;
  62. normalPay[i] = hours[i] * wageRate[i];
  63. }
  64.  
  65. // Calculate Gross Pay
  66. grossPay[i] = normalPay[i] + overtimePay[i];
  67. } // end for
  68.  
  69. // Print a nice table header
  70. printf("\n\n------------------------------------------------\n");
  71. printf("Clock# Wage Hours OT Gross\n");
  72. printf("------------------------------------------------\n");
  73.  
  74. // Now that we have all the information in our arrays, we can
  75. // Access each employee and print to screen or file
  76. for (i = 0; i < SIZE; i++)
  77. {
  78. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  79. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  80. }
  81.  
  82. return(0);
  83. }
Success #stdin #stdout 0s 5296KB
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