fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. // Declare constants
  5. #define STD_HOURS 40.0
  6. #define NUM_EMPLOYEES 5
  7. #define OVERTIME_RATE 1.5
  8. #define Size 5
  9.  
  10. // TODO: Declare and use one more constant
  11.  
  12. int main(){
  13. #define SIZE 5 /* symbolic constant for the array size */
  14.  
  15. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615}; // Employee clock number
  16. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  17. float hours [] = {51.0, 42.5, 37.0, 45.0, 0.0}; // Total hours worked in a week
  18. float normalPay ; // Standard weekly normal pay without overtime
  19. float overtimeHrs; // Any hours worked past the normal scheduled work week
  20. float overtimePay; // Additional overtime pay for any overtime hours worked
  21. float wageRate [] = {10.60, 9.75, 10.50, 12.25, 8.25};
  22. float totalPay = 0.00;
  23. float aveGross = 0.00;
  24.  
  25.  
  26.  
  27.  
  28. printf("\n***Pay Calculator***");
  29.  
  30. // Process each employee
  31. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  32. // Prompt the user for the clock number
  33. printf("\n\nEnter clock number: ");
  34. scanf("%d", &clockNumber[i]);
  35.  
  36. // Prompt the user for the wage rate
  37. printf("\nEnter wage rate: ");
  38. scanf("%f", &wageRate[i]);
  39.  
  40. // Prompt the user for the number of hours worked
  41. printf("\nEnter number of hours worked: ");
  42. scanf("%f", &hours[i]);
  43.  
  44. if (hours[i] > STD_HOURS) {
  45. // TODO: calculate the three values with overtime
  46. overtimeHrs = hours[i] - STD_HOURS;
  47. normalPay = STD_HOURS * wageRate[i];
  48. overtimePay = overtimeHrs * wageRate[i] * OVERTIME_RATE;
  49. } else {
  50. // TODO: calculate the three values without overtime
  51. overtimeHrs = 0.0;
  52. normalPay = hours[i] * wageRate[i];
  53. overtimePay = 0.0;
  54. }
  55. // Calculate the gross pay with normal pay and any additional overtime pay
  56. grossPay = normalPay + overtimePay;
  57. totalPay += grossPay;
  58. aveGross = totalPay / NUM_EMPLOYEES;
  59.  
  60.  
  61. // Print out information on the current employee
  62. // Optional TODO: Feel free to also print out normalPay and overtimePay
  63. printf("\n\nClock# Wage Hours OT Gross\n");
  64. printf("------------------------------------------------\n");
  65. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  66. clockNumber[i], wageRate[i], hours[i], overtimeHrs, grossPay);
  67.  
  68.  
  69. }
  70. // for
  71.  
  72. printf("\n------------------------------------------------\n");
  73. printf("Total Gross Pay: %8.2f\n", totalPay);
  74. printf("\n------------------------------------------------\n");
  75. printf("Average Gross Pay: %8.2f\n", aveGross);
  76.  
  77. return 0;
  78. } // main
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
***Pay Calculator***

Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage Hours OT Gross
------------------------------------------------
098401 10.60  51.0  11.0   598.90


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage Hours OT Gross
------------------------------------------------
526488  9.75  42.5   2.5   426.56


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage Hours OT Gross
------------------------------------------------
765349 10.50  37.0   0.0   388.50


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage Hours OT Gross
------------------------------------------------
034645 12.25  45.0   5.0   581.88


Enter clock number: 
Enter wage rate: 
Enter number of hours worked: 

Clock# Wage Hours OT Gross
------------------------------------------------
127615  8.25   0.0   0.0     0.00

------------------------------------------------
Total Gross Pay:	 1995.84

------------------------------------------------
Average Gross Pay:    399.17