//Jonathan Estrada CSC5 page#650 chapter 11 #15
/*************************************************************************
* COMPUTE PAY
* _______________________________________________________________________
* This program will compute the pay based on pay choice either hourly or
* salary. Then it will display it for the worker.
* _______________________________________________________________________
* INPUT
* payType : choice for type of pay
* hours Worked : hours worked
* hourlyRate : hourly rate
* salary : salary pay
* bonus : bonus for salary pay
*
* OUTPUT
* pay : pay based off pay type
* **********************************************************************/
#include <iostream>
#include <cctype>
using namespace std;
struct hourlyPaid
{
int hoursWorked;
float hourlyRate;
};
struct salaried
{
float salary;
float bonus;
};
union employee
{
hourlyPaid hours;
salaried paid;
};
int main() {
char payType;
float pay;
employee worker;
cout << "Please enter 'H' for hourly pay or 'S' for salary pay: ";
cin >> payType;
while(toupper(payType) != 'H' && toupper(payType) != 'S')
{
cout << "Invalid must be 'H' or 'S'" << endl;
cout << "Please enter 'H' for hourly pay or 'S' for salary pay: ";
cin >> payType;
}
if(toupper(payType) == 'H')
{
cout << "Please enter hours worked: ";
cin >> worker.hours.hoursWorked;
cout << worker.hours.hoursWorked << endl;
cout << "Please enter hourly rate: ";
cin >> worker.hours.hourlyRate;
cout << worker.hours.hourlyRate << endl;
pay = worker.hours.hoursWorked * worker.hours.hourlyRate;
cout << "Workers total hourly pay: $" << pay << endl;
}
else if(toupper(payType) == 'S')
{
cout << "Please enter salary: ";
cin >> worker.paid.salary;
cout << worker.paid.salary << endl;
cout << "Please enter bonus: ";
cin >> worker.paid.bonus;
cout << worker.paid.bonus << endl;
pay = worker.paid.salary + worker.paid.bonus;
cout << "Workers total salary pay is: $" << pay << endl;
}
return 0;
}