fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Sovanna Mann
  6. //
  7. // Class: C Programming, Fall 2024
  8. //
  9. // Date: 9/30/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 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. // Declare variables needed for the program
  27. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  28. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  29. float hours[SIZE]; // hours worked in a given week
  30. int i; // loop and array index
  31. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  32. float overtimePay[SIZE]; // overtime pay for a given week
  33. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  34.  
  35. printf("\n*** Pay Calculator ***\n\n");
  36.  
  37. // Process each employee one at a time
  38. for (i = 0; i < SIZE; i++)
  39. {
  40. // Prompt and Read in hours worked for employee
  41. printf("Enter hours worked for employee %08ld: ", clockNumber[i]);
  42. scanf("%f", &hours[i]);
  43.  
  44. // Calculate overtime and gross pay for employee
  45. if (hours[i] > STD_HOURS)
  46. {
  47. overtimeHrs[i] = hours[i] - STD_HOURS;
  48. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  49. }
  50. else // no OT
  51. {
  52. overtimeHrs[i] = 0;
  53. overtimePay[i] = 0;
  54. }
  55.  
  56. // Calculate Gross Pay
  57. grossPay[i] = (hours[i] - overtimeHrs[i]) * wageRate[i] + overtimePay[i];
  58. }
  59.  
  60. // Print a nice table header
  61. printf("--------------------------------------------------------------------------\n");
  62. printf(" Clock# Wage Hours OT Gross\n");
  63. printf("--------------------------------------------------------------------------\n");
  64.  
  65. // Now that we have all the information in our arrays, we can
  66. // Access each employee and print to screen or file
  67. for (i = 0; i < SIZE; i++)
  68. {
  69. printf("%08ld %6.2f %6.1f %6.1f %9.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  70. }
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 5284KB
stdin
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
stdout
*** Pay Calculator ***

Enter hours worked for employee 00098401: Enter hours worked for employee 00526488: Enter hours worked for employee 00765349: Enter hours worked for employee 00034645: Enter hours worked for employee 00127615: --------------------------------------------------------------------------
    Clock#   Wage   Hours      OT       Gross
--------------------------------------------------------------------------
00098401   10.60  98401.0  98361.0  1564364.00
00526488    9.75    10.6     0.0     103.35
00765349   10.50    51.0    11.0     593.25
00034645   12.25    11.0     0.0     134.75
00127615    8.35   598.9   558.9    7334.22