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);
  33.  
  34. // Prompt the user for the number of hours worked
  35. printf("\nEnter number of hours worked: ");
  36. scanf("%f", &hours);
  37.  
  38. if (hours[i] > STD_HOURS) {
  39. // TODO: calculate the three values with overtime
  40. } else {
  41. // TODO: calculate the three values without overtime
  42. }
  43. // Calculate the gross pay with normal pay and any additional overtime pay
  44. grossPay = normalPay + overtimePay;
  45.  
  46. // Print out information on the current employee
  47. // Optional TODO: Feel free to also print out normalPay and overtimePay
  48. printf("\n\nClock# Wage Hours OT Gross\n");
  49. printf("------------------------------------------------\n");
  50. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  51. clockNumber[i], wageRate[i], hours[i], overtimeHrs, grossPay);
  52. }
  53. // for
  54.  
  55. return 0;
  56. } // main
  57.  
  58.  
  59.  
Success #stdin #stdout 0.01s 5292KB
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   0.0     0.00


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

Clock# Wage Hours OT Gross
------------------------------------------------
526488  9.75  42.5   0.0     0.00


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

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


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

Clock# Wage Hours OT Gross
------------------------------------------------
034645 12.25  45.0   0.0     0.00


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