fork download
  1. //*******************************************************
  2.  
  3. //
  4.  
  5. // Assignment 4 - Arrays
  6.  
  7. //
  8.  
  9. // Name: <Tasos Paloukos>
  10.  
  11. //
  12.  
  13. // Class: C Programming, <Fall 2024>
  14.  
  15. //
  16.  
  17. // Date: <October 3,2024>
  18.  
  19. //
  20.  
  21. // Description: Program which determines overtime and
  22.  
  23. // gross pay for a set of employees with outputs sent
  24.  
  25. // to standard output (the screen).
  26.  
  27. //
  28.  
  29. //********************************************************
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. #include <stdio.h>
  39.  
  40. // constants to use
  41. #define SIZE 5 // number of employees to process
  42. #define STD_HOURS 40.0 // normal work week hours before overtime
  43. #define OT_RATE 1.5 // time and half overtime setting
  44.  
  45. int main()
  46. {
  47. // Declare variables needed for the program
  48. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  49. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  50. float hours[SIZE]; // hours worked in a given week
  51. int i; // loop and array index
  52. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  53. float overtimePay[SIZE]; // overtime pay for a given week
  54. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  55.  
  56. printf("\n*** Pay Calculator ***\n\n");
  57.  
  58. // Process each employee one at a time
  59. for (i = 0; i < SIZE; i++)
  60. {
  61. // Prompt and Read in hours worked for employee
  62. printf("Enter hours worked for employee %08ld: ", clockNumber[i]);
  63. scanf("%f", &hours[i]);
  64.  
  65. // Calculate overtime and gross pay for employee
  66. if (hours[i] > STD_HOURS)
  67. {
  68. overtimeHrs[i] = hours[i] - STD_HOURS;
  69. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  70. }
  71. else // no OT
  72. {
  73. overtimeHrs[i] = 0;
  74. overtimePay[i] = 0;
  75. }
  76.  
  77. // Calculate Gross Pay
  78. grossPay[i] = (hours[i] - overtimeHrs[i]) * wageRate[i] + overtimePay[i];
  79. }
  80.  
  81. // Print a nice table header
  82. printf("--------------------------------------------------------------------------\n");
  83. printf(" Clock# Wage Hours OT Gross\n");
  84. printf("--------------------------------------------------------------------------\n");
  85.  
  86. // Now that we have all the information in our arrays, we can
  87. // Access each employee and print to screen or file
  88. for (i = 0; i < SIZE; i++)
  89. {
  90. printf("%08ld %6.2f %6.1f %6.1f %9.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  91. }
  92.  
  93. return 0;
  94. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
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  -100190974912008235151082632773632.0     0.0  -1062024349541537783668729343639552.00
00526488    9.75     0.0     0.0       0.00
00765349   10.50    -0.0     0.0      -0.00
00034645   12.25     0.0     0.0       0.00
00127615    8.35     0.0     0.0       0.00