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.  
  14. int clockNumber [] = {98401, 526488, 765349, 34645, 127615}; // Employee clock number
  15. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  16. float hours [] = {51.0, 42.5, 37.0, 45.0, 0.0}; // Total hours worked in a week
  17. float normalPay ; // Standard weekly normal pay without overtime
  18. float overtimeHrs; // Any hours worked past the normal scheduled work week
  19. float overtimePay; // Additional overtime pay for any overtime hours worked
  20. float wageRate [] = {10.60, 9.75, 10.50, 12.25, 8.25};
  21.  
  22. printf("\n***Pay Calculator***");
  23.  
  24. // Process each employee
  25. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  26. // Prompt the user for the clock number
  27. printf("\n\nEnter clock number: ");
  28. scanf("%d", &clockNumber[i]);
  29.  
  30. // Prompt the user for the wage rate
  31. printf("\nEnter wage rate: ");
  32. scanf("%f", &wageRate[i]);
  33.  
  34. // Prompt the user for the number of hours worked
  35. printf("\nEnter number of hours worked: ");
  36. scanf("%f", &hours[i]);
  37.  
  38. if (hours[i] > STD_HOURS) {
  39. // TODO: calculate the three values with overtime
  40. overtimeHrs = hours[i] - STD_HOURS;
  41. normalPay = STD_HOURS * wageRate[i];
  42. overtimePay = overtimeHrs * wageRate[i] * OVERTIME_RATE;
  43. } else {
  44. // TODO: calculate the three values without overtime
  45. overtimeHrs = 0.0;
  46. normalPay = hours[i] * wageRate[i];
  47. overtimePay = 0.0;
  48. }
  49. // Calculate the gross pay with normal pay and any additional overtime pay
  50. grossPay = normalPay + overtimePay;
  51.  
  52. // Print out information on the current employee
  53. // Optional TODO: Feel free to also print out normalPay and overtimePay
  54. printf("\n\nClock# Wage Hours OT Gross\n");
  55. printf("------------------------------------------------\n");
  56. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  57. clockNumber[i], wageRate[i], hours[i], overtimeHrs, grossPay);
  58. }
  59. // for
  60.  
  61. return 0;
  62. } // main
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
Success #stdin #stdout 0.01s 5320KB
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