structure and unions

im trying to use two structure with a union of two member
dont know if i am declaring it right or not


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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

struct HourlyPaid
{
	double HoursWorked;
	double HourlyRate;
};

struct Salaried
{
	double Salary;
	double Bonus;
};

union PaySource
{
	double hours;
	double salaray;``````
};

int main()
{
	PaySource workers;
	char payType;
	double hour1;
	double salary1;
	double payRate;
	double grossPay;
	double bonus = 150;

	cout << fixed << showpoint << setprecision(2);
	cout << "This program calculates either HourlyPaid or Salaried.\n";
	cout << "------------------------------------------------------\n";

	cout << "Enter (H) for HourlyPaid or (S) for Salaried: ";
	cin >> payType;

	if (payType == 'H' || payType == 'h')
	{
		cout << "\nWhat is the hourly pay rate? $";
		cin >> payRate;

		while (payRate < 0)
		{
			cout << "Please enter a number greater than zero: ";
			cin >> payRate;
		}
		
		cout << "How many hours were worked? ";
		cin >> hours;
		hour1 = hours;

		while (hours > 80)
		{
			cout << "Please enter number less than 80: ";
			cin >> hours;
			hour1 = hours;
		}
		
		grossPay = hours * payRate;
		cout << "The Hourly Paid was pay: $" << grossPay << endl;
	}

	else if(payType == 'S' || payType == 's')
	{
		cout << "\nWhat is the regular salary for this employee? $";
		cin >> salary;
		salary1 = salary;

		
		cout << "The employee bonus is: $" << bonus << endl;
		grossPay = salary + bonus;
		cout << "This employee salary plus bonus is: $" << grossPay << endl;
	}
	
	else
	{
		cout << payType << " \nis not a valid selection.\n";
		cout << "Please close the program and run again.\n";
		cout << "Remember to chose (H) for HourlyPaid or (S) for Salaried\n";
		
	}
	return 0;
}
Well, you might want to remove the extra ` characters...other then that, it looks fine (although you aren't actually using any of the structs (classes) you are defining)
Topic archived. No new replies allowed.