fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <replace with your name>
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  8. //
  9. // Date: <replace with the current date>
  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. /* Define constants */
  20. #define SIZE 5 // Number of employees
  21. #define STD_HOURS 40.0 // Standard hours before overtime
  22. #define OT_RATE 1.5 // Overtime pay multiplier
  23.  
  24. int main() {
  25. /* Employee Data */
  26. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  27. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  28.  
  29. /* Input and Output Data */
  30. float hoursWorked[SIZE]; // To be entered by user
  31. float overtimeHours[SIZE]; // To be calculated
  32. float grossPay[SIZE]; // To be calculated
  33.  
  34. int i; // loop index
  35.  
  36. printf("*** Pay Calculator ***\n\n");
  37.  
  38. // Input Loop
  39. for (i = 0; i < SIZE; i++) {
  40. printf("Enter hours worked for employee #%06ld: ", clockNumber[i]);
  41. scanf("%f", &hoursWorked[i]);
  42.  
  43. // Calculate overtime hours
  44. if (hoursWorked[i] > STD_HOURS) {
  45. overtimeHours[i] = hoursWorked[i] - STD_HOURS;
  46. } else {
  47. overtimeHours[i] = 0.0;
  48. }
  49.  
  50. // Calculate gross pay
  51. float normalPay = (hoursWorked[i] > STD_HOURS ? STD_HOURS : hoursWorked[i]) * wageRate[i];
  52. float overtimePay = overtimeHours[i] * wageRate[i] * OT_RATE;
  53. grossPay[i] = normalPay + overtimePay;
  54. }
  55.  
  56. // Output
  57. printf("\n--------------------------------------------------------------------------\n");
  58. printf(" Clock# Wage Hours OT Gross\n");
  59. printf("--------------------------------------------------------------------------\n");
  60.  
  61. for (i = 0; i < SIZE; i++) {
  62. printf(" %06ld %5.2f %5.1f %6.1f %8.2f\n",
  63. clockNumber[i],
  64. wageRate[i],
  65. hoursWorked[i],
  66. overtimeHours[i],
  67. grossPay[i]);
  68. }
  69.  
  70. return 0;
  71. }
Success #stdin #stdout 0s 5312KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for employee #098401: Enter hours worked for employee #526488: Enter hours worked for employee #765349: Enter hours worked for employee #034645: Enter hours worked for employee #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