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. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  26. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  27. float hours[SIZE];
  28. float overtimeHrs[SIZE], normalPay[SIZE], overtimePay[SIZE], grossPay[SIZE];
  29. int i;
  30. float totalHours = 0, totalOvertimeHrs = 0, totalOvertimePay = 0, totalGrossPay = 0;
  31.  
  32. printf("\n*** Pay Calculator ***\n\n");
  33.  
  34. for (i = 0; i < SIZE; i++) {
  35. scanf("%f", &hours[i]);
  36. }
  37.  
  38. for (i = 0; i < SIZE; i++) {
  39. if (hours[i] > STD_HOURS) {
  40. overtimeHrs[i] = hours[i] - STD_HOURS;
  41. normalPay[i] = STD_HOURS * wageRate[i];
  42. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  43. } else {
  44. overtimeHrs[i] = 0;
  45. normalPay[i] = hours[i] * wageRate[i];
  46. overtimePay[i] = 0;
  47. }
  48. grossPay[i] = normalPay[i] + overtimePay[i];
  49.  
  50. totalHours += hours[i];
  51. totalOvertimeHrs += overtimeHrs[i];
  52. totalOvertimePay += overtimePay[i];
  53. totalGrossPay += grossPay[i];
  54. }
  55.  
  56. printf("\n%-10s %-10s %-10s %-10s %-10s %-10s\n", "Clock#", "Wage", "Hours", "OT Hours", "OT Pay", "Gross Pay");
  57. printf("-------------------------------------------------------------------------------\n");
  58.  
  59. for (i = 0; i < SIZE; i++) {
  60. printf("%06ld $%7.2f %7.2f %7.2f $%7.2f $%7.2f\n",
  61. clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], overtimePay[i], grossPay[i]);
  62. }
  63.  
  64. printf("-------------------------------------------------------------------------------\n");
  65. printf("%-10s %-10s %7.2f %7.2f $%7.2f $%7.2f\n", "TOTALS", "", totalHours, totalOvertimeHrs, totalOvertimePay, totalGrossPay);
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5280KB
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