Help with Nested Structure

I was wondering how is the proper way to do the calculations using a nested structure. I was asked to write a program that contained a nested structure and calculate a weekly payroll. One structure held the departments and calculations(manager, sales associate) and another structure contained ID, Hours and Rate. I then had to ask for each individual employee's ID, hours and rate in which I understood what to do. But once I got to the calculations for the gross pay, federal tax and other calculations for each employee is where I got lost. What direction do I need to go in order to calculate the 9 employees with little code?


#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

//Create Structures

struct Department //structure for pay calculations & department category
{
char dept;
double gpay;
double overtime;
double fedtax;
double oasditax;
double hitax;
double npay;
};

struct Empinfo //structure for employee id, rate & hours
{
Department d1 ;
int ID;
double rate;
double hours;
};

int main()

{

//Number of managers, salespersons and bookkeepers

Empinfo m1, m2, s1, s2, s3, s4, b1, b2, b3;


//Assigned tax values

m1.d1.oasditax = 0.062;
m2.d1.oasditax = 0.062;
s1.d1.oasditax = 0.062;
s2.d1.oasditax = 0.062;
s3.d1.oasditax = 0.062;
s4.d1.oasditax = 0.062;
b1.d1.oasditax = 0.062;
b2.d1.oasditax = 0.062;
b3.d1.oasditax = 0.062;
m1.d1.hitax = 0.0145;
m2.d1.hitax = 0.0145;
s1.d1.hitax = 0.0145;
s2.d1.hitax = 0.0145;
s3.d1.hitax = 0.0145;
s4.d1.hitax = 0.0145;
b1.d1.hitax = 0.0145;
b2.d1.hitax = 0.0145;
b3.d1.hitax = 0.0145;

//Prompt user for payroll data

cout << "Please enter Manager ID: ";
cin >> m1.ID;

cout << "\nPlease enter Manager rate of pay: ";
cin >> m1.rate;

cout << "\nPlease enter Manager hours worked this week: ";
cin >> m1.hours;

cout << "\nPlease enter Manager ID: ";
cin >> m2.ID;

cout << "\nPlease enter Manager rate of pay: ";
cin >> m2.rate;

cout << "\nPlease enter Manager hours worked this week: ";
cin >> m2.hours;

cout << "\nPlease enter Sales Associate ID: ";
cin >> s1.ID;

cout << "\nPlease enter Sales Associate rate of pay: ";
cin >> s1.rate;

cout << "\nPlease enter Sales Assoicate hours worked this week: ";
cin >> s1.hours;

cout << "\nPlease enter Sales Associate ID: ";
cin >> s2.ID;

cout << "\nPlease enter Sales Associate rate of pay: ";
cin >> s2.rate;

cout << "\nPlease enter Sales Assoicate hours worked this week: ";
cin >> s2.hours;

cout << "\nPlease enter Sales Associate ID: ";
cin >> s3.ID;

cout << "\nPlease enter Sales Associate rate of pay: ";
cin >> s3.rate;

cout << "\nPlease enter Sales Assoicate hours worked this week: ";
cin >> s3.hours;

cout << "\nPlease enter Sales Associate ID: ";
cin >> s4.ID;

cout << "\nPlease enter Sales Associate rate of pay: ";
cin >> s4.rate;

cout << "\nPlease enter Sales Assoicate hours worked this week: ";
cin >> s4.hours;

cout << "\nPlease enter Book Keeper ID: ";
cin >> b1.ID;

cout << "\nPlease enter Book Keeper rate of pay: ";
cin >> b1.rate;

cout << "\nPlease enter Book Keeper hours worked: ";
cin >> b1.hours;

cout << "\nPlease enter Book Keeper ID: ";
cin >> b2.ID;

cout << "\nPlease enter Book Keeper rate of pay: ";
cin >> b2.rate;

cout << "\nPlease enter Book Keeper hours worked: ";
cin >> b2.hours;

cout << "\nPlease enter Book Keeper ID: ";
cin >> b3.ID;

cout << "\nPlease enter Book Keeper rate of pay: ";
cin >> b3.rate;

cout << "\nPlease enter Book Keeper hours worked: ";
cin >> b3.hours;


//Calculate data, how do I get all of the user's data into this formula?

if (hours > 40)

{
overtime = hours-40;
hours = 40;
}

gpay = (hours * rate) + (overtime * rate * 1.5);

oasditax = gpay * oasditax;

hitax = gpay * hitax;

if (gpay <= 101)
{
fedtax = 0.058;
}
else if ( gpay >= 101.01 && gpay <= 201)
{
fedtax = 0.153;
}
else if (gpay >= 201.01 && gpay <= 351)
{
fedtax = 0.184;
}
else if (gpay >= 351.01 && gpay <= 502)
{
fedtax = 0.239;
}
else
{
fedtax = 0.288;
}

fedtax = fedtax * gpay;

npay = gpay - oasditax - hitax - fedtax;


Topic archived. No new replies allowed.