I have this function which reads in a workers.age from a structure. It determines how much taxes that worker will have to pay based on a base salary that is also passed to that function.
I am able to print out the net salary and amount of taxes paid for each person. What I need to do now is sort that list according to the net pay and display in descending order the net salary and worker name.
I have tried inserting a bubble sort into this function but cannot get this to work. How can I place a sort into this function? Or must I use another function?
Thank you.
void tax_paid (person worker[], double base[], const int emps) //7.Takes in age, base pay and amnt of employees.
{
double t=0;
double tax = 0;
double mosttax = 0;
double net=0;
int index; //Variable for tax rate.
bool swap;
for (int i=0;i<emps;i++)
{
if (worker[i].age >= 55) //Determines tax rate based on age.
{
tax = (base[i] * .50);
net = base[i]-tax; //Assigns net pay to "net"
cout << worker[i].lname << " " << left << setw(10)<< worker[i].fname << " Earned after taxes: $" << net << " Tax rate: $" << tax << "\n";
}
else
{
tax = (base[i] * .10);
net = base[i]-tax;
cout << worker[i].lname << " " << left << setw(10)<< worker[i].fname << " Earned after taxes: $" << net << " Tax rate: $" << tax << "\n"; //Displays Total paid taxes and tax amount.
}
if (tax > mosttax)
{ //Determines employee who paid most in taxes.
mosttax=tax;
index=i;
}
}
//Displays name and taxes paid to employee who paid most in taxes.
cout << "\n";
cout << worker[index].lname << " " << worker[index].fname << " Paid the most in taxes: $" << mosttax << " \n";
cout << "\n";
}