Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This program calculates gross pay.
- #include <iostream>
- #include <iomanip>
- using namespace std;
- // Global constant.
- const double PAY_RATE = 22.55;
- const double BASE_HOURS = 40.0;
- const double OT_MULTIPLIER = 1.5;
- // Function prototypes.
- double getBasePay(double);
- double getOvertimePay(double);
- int main()
- {
- double hours,
- basePay,
- overtime = 0.0,
- totalPay;
- // Get the number of hours worked.
- cout << "How many hours did you work? ";
- cin >> hours;
- // Get the amount of base pay.
- basePay = getBasePay(hours);
- // Get overtime pay, if any.
- if (hours > BASE_HOURS)
- {
- overtime = getOvertimePay(hours);
- }
- // Calculate the total pay.
- totalPay = basePay + overtime;
- // Set up numeric formatting.
- cout << fixed << showpoint << setprecision(2);
- // Display the pay.
- cout << "Base pay: $" << basePay << endl;
- cout << "Overtime pay: $" << overtime << endl;
- cout << "Total pay: $" << totalPay << endl;
- }
- //**************************************************
- // The getBasePay function accepts the number of *
- // hours worked as an argument and returns the *
- // employee's pay for non-overtime hours. *
- //**************************************************
- double getBasePay(double hoursWorked)
- {
- double basePay; // To hold base pay.
- // Determine base pay.
- if (hoursWorked > BASE_HOURS)
- {
- basePay = BASE_HOURS * PAY_RATE;
- }
- else
- {
- basePay = hoursWorked * PAY_RATE;
- }
- return basePay;
- }
- //**************************************************
- // The getOvertimepPay function accepts the number *
- // of hours worked as an argument and returns the *
- // employee's overtime pay. *
- //**************************************************
- double getOvertimePay(double hoursWorked)
- {
- double overtimePay; // To hold the overtime pay.
- // Determine overtime pay.
- if (hoursWorked > BASE_HOURS)
- {
- overtimePay = (hoursWorked - BASE_HOURS) *
- PAY_RATE * OT_MULTIPLIER;
- }
- else
- {
- overtimePay = 0.0;
- }
- return overtimePay;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement