fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Larson Klipic
  6. //
  7. // Class: C Programming, summer 26
  8. //
  9. // Date: JUN 20th
  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. // constants to use
  20. #define SIZE 5 // number of employees to process
  21. #define STD_HOURS 40.0 // normal work week hours before overtime
  22. #define OT_RATE 1.5 // time and half overtime setting
  23.  
  24. int main()
  25. {
  26.  
  27. // unique employee identifier
  28. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  29.  
  30. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  31. float hours [SIZE]; // hours worked in a given week
  32. int i; // loop and array index
  33. float normalPay [SIZE]; // normal weekly pay without any overtime
  34. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  35. float overtimePay [SIZE]; // overtime pay for a given week
  36.  
  37. // hourly pay for each employee
  38. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  39.  
  40. printf ("\n*** Pay Calculator ***\n\n");
  41.  
  42. // Process each employee one at a time
  43. for (i = 0; i < SIZE; i++)
  44. {
  45. // Asking for hours worked
  46. printf("Enter how many hours the employee worked:\n");
  47. scanf("%f", &hours[i]);
  48.  
  49. // Calculate overtime and gross pay for employee
  50. if (hours[i] >= STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS;
  53. normalPay[i] = wageRate [i] * STD_HOURS;
  54. overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
  55.  
  56. }
  57. else // no OT
  58. {
  59. overtimeHrs[i] = 0;
  60. overtimePay[i] = 0;
  61.  
  62. normalPay[i] = wageRate[i] * hours[i];
  63. }
  64.  
  65. // Calculate Gross Pay
  66. grossPay[i] = normalPay[i] + overtimePay[i];
  67. }
  68.  
  69. // Table Header
  70. printf("\n\nClock# Wage Hours Pay OT-Hrs OT-Pay Gross\n");
  71. printf("-------------------------------------------------------------\n");
  72.  
  73.  
  74. // print out all of the emlployees pay information
  75. for (i = 0; i < SIZE; i++)
  76. {
  77. printf("%06li %5.2f %5.1f %7.2f %6.1f %6.2f %7.2f\n",
  78. clockNumber[i], wageRate[i], hours[i], normalPay[i],
  79. overtimeHrs[i], overtimePay[i], grossPay[i]);
  80. }
  81.  
  82. return(0);
  83. }
Success #stdin #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter how many hours the employee worked:
Enter how many hours the employee worked:
Enter how many hours the employee worked:
Enter how many hours the employee worked:
Enter how many hours the employee worked:


Clock#   Wage   Hours      Pay      OT-Hrs  OT-Pay    Gross
-------------------------------------------------------------
098401   10.60    51.0    424.00     11.0   174.90    598.90
526488    9.75    42.5    390.00      2.5    36.56    426.56
765349   10.50    37.0    388.50      0.0     0.00    388.50
034645   12.25    45.0    490.00      5.0    91.88    581.88
127615    8.35     0.0      0.00      0.0     0.00      0.00