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