-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMulipurposePayRoll.cpp
61 lines (52 loc) · 1.1 KB
/
MulipurposePayRoll.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Programming Challenge 15. This program will calculate
// the pay for either an hourly paid worker or salaried
// worker
#include <iostream>
#include <iomanip>
using namespace std;
struct HourlyPaid
{
float hoursWorked;
float HourlyRAte;
};
struct Salaried
{
float salary;
float bonus;
};
union PayRoll
{
HourlyPaid h;
Salaried s;
};
int main()
{
PayRoll p;
char payType;
float payRate;
float grossPay;
cout << fixed << showpoint << setprecision(2);
// Gets the pay type, hourly or salary
cout << "Hourly(H) or Salaried(S)? ";
cin >> payType;
// Determine gross pay according to the pay type
if (payType == 'H')
{
cout << "Enter the number of hours worked: ";
cin >> p.h.hoursWorked;
cout << "Enter the hourly pay rate: ";
cin >> p.h.HourlyRAte;
grossPay = p.h.hoursWorked * p.h.HourlyRAte;
cout << "Gross Pay: " << grossPay << endl;
}
else if (payType == 'S')
{
cout << "Enter the salary amount: ";
cin >> p.s.salary;
cout << "Enter the bonus amount: ";
cin >> p.s.bonus;
grossPay = p.s.salary + p.s.bonus;
cout << "Gross Pay: " << grossPay << endl;
}
return 0;
}