fork download
  1. /******************************************************
  2.  *
  3.  * Assignment 4 - Arrays
  4.  *
  5.  * Name: Robert Hyde
  6.  *
  7.  * Class: C Programming, Fall 2026
  8.  *
  9.  * Date: September 28, 2026
  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 */
  22. #define OT_RATE 1.5 /* time and a half overtime setting */
  23.  
  24. int main()
  25. {
  26. /* Declare variables needed for the program */
  27.  
  28. /* Unique employee identifier */
  29. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  30.  
  31. /* Hourly pay for each employee */
  32. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  33.  
  34. /* Arrays for employee information and calculations */
  35. float hours[SIZE];
  36. float overtimeHrs[SIZE];
  37. float normalPay[SIZE];
  38. float overtimePay[SIZE];
  39. float grossPay[SIZE];
  40.  
  41. int i;
  42.  
  43. printf("\n*** Pay Calculator ***\n\n");
  44.  
  45. /* Process each employee one at a time */
  46. for (i = 0; i < SIZE; i++)
  47. {
  48. /* Prompt for and read hours worked */
  49. printf("Enter hours worked for employee %ld: ", clockNumber[i]);
  50. scanf("%f", &hours[i]);
  51.  
  52. /* Calculate overtime and gross pay */
  53. if (hours[i] > STD_HOURS)
  54. {
  55. overtimeHrs[i] = hours[i] - STD_HOURS;
  56.  
  57. normalPay[i] = STD_HOURS * wageRate[i];
  58.  
  59. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  60. }
  61. else
  62. {
  63. overtimeHrs[i] = 0.0;
  64.  
  65. normalPay[i] = hours[i] * wageRate[i];
  66.  
  67. overtimePay[i] = 0.0;
  68. }
  69.  
  70. /* Calculate gross pay */
  71. grossPay[i] = normalPay[i] + overtimePay[i];
  72. }
  73.  
  74. /* Print table header */
  75. printf("\n--------------------------------------------------------------------------\n");
  76. printf(" Clock# Wage Hours OT Gross\n");
  77. printf("--------------------------------------------------------------------------\n");
  78.  
  79. /* Print employee information */
  80. for (i = 0; i < SIZE; i++)
  81. {
  82. printf(" %06ld %5.2f %5.1f %5.1f %8.2f\n",
  83. clockNumber[i],
  84. wageRate[i],
  85. hours[i],
  86. overtimeHrs[i],
  87. grossPay[i]);
  88. }
  89.  
  90. printf("--------------------------------------------------------------------------\n");
  91.  
  92. return 0;
  93. }
Success #stdin #stdout 0s 5296KB
stdin
098401
10.60
51.0
526488
9.75
42.5
765349
10.50
37.0
034645
12.25
45.0
127615
8.35
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee 98401: Enter hours worked for employee 526488: Enter hours worked for employee 765349: Enter hours worked for employee 34645: Enter hours worked for employee 127615: 
--------------------------------------------------------------------------
    Clock#   Wage  Hours    OT       Gross
--------------------------------------------------------------------------
    098401  10.60  98401.0   98361.0    1564364.00
    526488   9.75   10.6     0.0      103.35
    765349  10.50   51.0    11.0      593.25
    034645  12.25  526488.0   526448.0    9673972.00
    127615   8.35    9.8     0.0       81.41
--------------------------------------------------------------------------