Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. // This program calculates gross pay.
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. // Global constant.
  7. const double PAY_RATE = 22.55;
  8. const double BASE_HOURS = 40.0;
  9. const double OT_MULTIPLIER = 1.5;
  10.  
  11. // Function prototypes.
  12. double getBasePay(double);
  13. double getOvertimePay(double);
  14.  
  15. int main()
  16. {
  17.     double hours,
  18.         basePay,
  19.         overtime = 0.0,
  20.         totalPay;
  21.  
  22.     // Get the number of hours worked.
  23.     cout << "How many hours did you work? ";
  24.     cin >> hours;
  25.  
  26.     // Get the amount of base pay.
  27.     basePay = getBasePay(hours);
  28.  
  29.     // Get overtime pay, if any.
  30.     if (hours > BASE_HOURS)
  31.     {
  32.         overtime = getOvertimePay(hours);
  33.     }
  34.  
  35.     // Calculate the total pay.
  36.     totalPay = basePay + overtime;
  37.  
  38.     // Set up numeric formatting.
  39.     cout << fixed << showpoint << setprecision(2);
  40.  
  41.     // Display the pay.
  42.     cout << "Base pay: $" << basePay << endl;
  43.     cout << "Overtime pay: $" << overtime << endl;
  44.     cout << "Total pay: $" << totalPay << endl;
  45. }
  46.  
  47. //**************************************************
  48. // The getBasePay function accepts the number of    *
  49. // hours worked as an argument and returns the      *
  50. // employee's pay for non-overtime hours.           *
  51. //**************************************************
  52.  
  53. double getBasePay(double hoursWorked)
  54. {
  55.     double basePay; // To hold base pay.
  56.  
  57.     // Determine base pay.
  58.     if (hoursWorked > BASE_HOURS)
  59.     {
  60.         basePay = BASE_HOURS * PAY_RATE;
  61.     }
  62.     else
  63.     {
  64.         basePay = hoursWorked * PAY_RATE;
  65.     }
  66.     return basePay;
  67. }
  68.  
  69. //**************************************************
  70. // The getOvertimepPay function accepts the number  *
  71. // of hours worked as an argument and returns the   *
  72. // employee's overtime pay.                     *
  73. //**************************************************
  74.  
  75. double getOvertimePay(double hoursWorked)
  76. {
  77.     double overtimePay; // To hold the overtime pay.
  78.  
  79.     // Determine overtime pay.
  80.     if (hoursWorked > BASE_HOURS)
  81.     {
  82.         overtimePay = (hoursWorked - BASE_HOURS) *
  83.             PAY_RATE * OT_MULTIPLIER;
  84.     }
  85.     else
  86.     {
  87.         overtimePay = 0.0;
  88.     }
  89.  
  90.     return overtimePay;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement