fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Amir Gharouadi>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <02/22/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 before overtime
  22. #define OT_RATE 1.5 // time and half overtime setting
  23.  
  24. int main()
  25. {
  26. // unique employee identifier
  27. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  28.  
  29. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  30. float hours[SIZE]; // hours worked in a given week
  31. int i; // loop and array index
  32. float normalPay[SIZE]; // normal weekly pay without any overtime
  33. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  34. float overtimePay[SIZE]; // overtime pay for a given week
  35.  
  36. // hourly pay for each employee
  37. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  38.  
  39. printf("\n*** Pay Calculator ***\n\n");
  40.  
  41. // Process each employee one at a time
  42. for (i = 0; i < SIZE; i++)
  43. {
  44. // Prompt and Read in hours worked for employee
  45. printf("Enter number of hours worked for clock #%06ld: ", clockNumber[i]);
  46. scanf("%f", &hours[i]);
  47.  
  48. // Calculate overtime and gross pay for employee
  49. if (hours[i] > STD_HOURS)
  50. {
  51. overtimeHrs[i] = hours[i] - STD_HOURS;
  52.  
  53. // Calculate normalPay and overtimePay with overtime
  54. normalPay[i] = wageRate[i] * STD_HOURS;
  55. overtimePay[i] = (OT_RATE * wageRate[i]) * overtimeHrs[i];
  56. }
  57. else // no OT
  58. {
  59. overtimeHrs[i] = 0.0;
  60.  
  61. // Calculate normalPay and overtimePay without overtime
  62. normalPay[i] = wageRate[i] * hours[i];
  63. overtimePay[i] = 0.0;
  64. }
  65.  
  66. // Calculate Gross Pay
  67. grossPay[i] = normalPay[i] + overtimePay[i];
  68. }
  69.  
  70. // Print a nice table header
  71. printf("\n--------------------------------------------------------------------------\n");
  72. printf(" Clock# Wage Hours OT Gross\n");
  73. printf("--------------------------------------------------------------------------\n");
  74.  
  75. // Print employee information from your arrays
  76. for (i = 0; i < SIZE; i++)
  77. {
  78. printf(" %06ld %6.2f %6.1f %6.1f %10.2f\n",
  79. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  80. }
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0s 5316KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter number of hours worked for clock #098401: Enter number of hours worked for clock #526488: Enter number of hours worked for clock #765349: Enter number of hours worked for clock #034645: Enter number of hours worked for clock #127615: 
--------------------------------------------------------------------------
    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