fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Marin Haxhiaj
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: 02/20/2025
  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.  
  20. #define SIZE 5 // Number of employees to process
  21. #define STD_HOURS 40.0 // Standard work week hours before overtime
  22. #define OT_RATE 1.5 // Overtime pay factor
  23.  
  24. int main() {
  25.  
  26. // Declare variables needed for the program
  27. // Recommend an array for clock, wage, hours,
  28. // ... and overtime hours and gross.
  29. // Recommend arrays also for normal pay and overtime pay
  30. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  31.  
  32. // unique employee identifier
  33. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  34.  
  35. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; //hourly pay
  36. float hours[SIZE];
  37. float overtimeHrs[SIZE];
  38. float normalPay[SIZE];
  39. float overtimePay[SIZE];
  40. float grossPay[SIZE];
  41. int i;
  42.  
  43. float totalHours = 0, totalOvertimeHrs = 0, totalOvertimePay = 0, totalGrossPay = 0;
  44.  
  45. printf("\n**************************************\n");
  46. printf("* Pay Calculator *\n");
  47. printf("**************************************\n\n"); //Table Header
  48.  
  49. for (i = 0; i < SIZE; i++) {
  50. scanf("%f", &hours[i]);
  51. }
  52.  
  53. for (i = 0; i < SIZE; i++) {
  54. if (hours[i] > STD_HOURS) {
  55. overtimeHrs[i] = hours[i] - STD_HOURS;
  56. normalPay[i] = STD_HOURS * wageRate[i];
  57. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  58. } else {
  59. overtimeHrs[i] = 0;
  60. normalPay[i] = hours[i] * wageRate[i];
  61. overtimePay[i] = 0;
  62. }
  63. grossPay[i] = normalPay[i] + overtimePay[i];
  64.  
  65. totalHours += hours[i];
  66. totalOvertimeHrs += overtimeHrs[i];
  67. totalOvertimePay += overtimePay[i];
  68. totalGrossPay += grossPay[i];
  69. }
  70.  
  71. printf("\n%-10s %-10s %-10s %-10s %-10s %-10s\n", "Clock#", "Wage", "Hours", "OT Hours", "OT Pay", "Gross Pay");
  72. printf("-------------------------------------------------------------------------------\n");
  73.  
  74. for (i = 0; i < SIZE; i++) {
  75. printf("%06ld $%7.2f %7.2f %7.2f $%7.2f $%7.2f\n",
  76. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], overtimePay[i], grossPay[i]);
  77. }
  78.  
  79. printf("-------------------------------------------------------------------------------\n");
  80. printf("%-10s %-10s %7.2f %7.2f $%7.2f $%7.2f\n", "TOTALS", "", totalHours, totalOvertimeHrs, totalOvertimePay, totalGrossPay);
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0s 5292KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
**************************************
*           Pay Calculator            *
**************************************


Clock#     Wage       Hours      OT Hours   OT Pay     Gross Pay 
-------------------------------------------------------------------------------
098401   $  10.60     51.00     11.00   $ 174.90   $ 598.90
526488   $   9.75     42.50      2.50   $  36.56   $ 426.56
765349   $  10.50     37.00      0.00   $   0.00   $ 388.50
034645   $  12.25     45.00      5.00   $  91.88   $ 581.88
127615   $   8.35      0.00      0.00   $   0.00   $   0.00
-------------------------------------------------------------------------------
TOTALS                 175.50     18.50   $ 303.34   $1995.84