Задача:
▼Прихований текст
Multipurpose Payroll. Write a program that calculates pay for either an hourly paid worker or a
salaried worker. Hourly paid workers are paid their hourly pay rate times the number of hours worked.
Salaried workers are paid their regular salary plus any bonus they may have earned.
The program should declare two structures for the following data:
Hourly Paid: HoursWorked, HourlyRate
Salaried: Salary, Bonus
The program should also declare a union with two members. Each member should be a structure variable:
one for the hourly paid worker and another for the salaried worker.
The program should ask the user whether he or she is calculating the pay for an hourly paid worker or
a salaried worker. Regardless of which the user selects, the appropriate members of the union will be used
to store the data that will be used to calculate the pay.
Input Validation: Do not accept negative numbers. Do not accept values greater than 80 for HoursWorked.
Як я зрозуміла, мені необхідно створити дві структури. Ось вони:
struct HourlyPaid
{
int hours_worked;
double hourlyrate;
};
struct Salaried
{
double salary;
double bonus;
};
і створити Union з полями: одне поле - типу перша структура, друге - друга структура. Я це зробила так:
union Workers
{
HourlyPaid first_worker;
Salaried second_worker;
};
Але я невпевнена чи це правильно, можливо я не так умову переклала.
Допоможіть, будь ласка, зробити правильно.
P.S. Яке в даному випадку практичне значення юніон, чому не просто окремі дві змінні?