rendered paste body#include <stdio.h>
struct employee {
char *name;
int age;
int classification;
int hours_worked;
float overtime;
float gross_salary;
float net_salary;
};
struct employee descend_order(struct employee descend){
int left, right;
struct employee temp;
for ( left = 0; left < 4; ++left ) //nested for loop for arrays once the right arrays loop is done the left will advance one untill all arrays are checked
for ( right = left + 1; right < 5; ++right)
if ( descend.net_salary[left] < descend.net_salary[right] ) //if the left data is larger then right data, then it will execute the following
{
temp = descend.net_salary[left]; // temp is set to the left integer
descend.net_salary[left] = descend.net_salary[right]; //the left data is swaped with the right data
descend.net_salary[right] = temp; //the right data is now set to the temp value
}
}
}
int main (void)
{
struct employee descend_order(struct employee descend);
struct employee emp;
struct employee data[5] =
{ {"John Miller", 42, 2, 38}, {"Michael Wick", 34, 1, 34}, {"Maria Garcia", 30, 3, 25},
{"Jose Garcia", 27, 4, 45}, {"Nathan Aston", 24, 1, 55}
};
int i;
printf("Original Data Below \n");
printf("--------------------------------------------------------------------------------------------------\n");
for (i = 0; i<=4; ++i) {
if(data[i].hours_worked < 41) {
if(data[i].classification == 1){
emp.gross_salary = data[i].hours_worked * 10.25;
} //end of class 1
else if(data[i].classification ==2){
emp.gross_salary = data[i].hours_worked *8.50;
} //end of class 2
else if(data[i].classification == 3) {
emp.gross_salary = data[i].hours_worked *6.30;
} //end of class 3
else if (data[i].classification == 4) {
emp.gross_salary = data[i].hours_worked *4.65;
} //end of class 4
} // end of if loop <= 40 hours
else{
if(data[i].classification == 1){
emp.overtime = (data[i].hours_worked - 40) * 10.25;
emp.gross_salary = data[i].hours_worked *10.25 + emp.overtime;
} //end of class 1
else if(data[i].classification ==2){
emp.overtime = (data[i].hours_worked - 40) *8.50;
emp.gross_salary = data[i].hours_worked *8.50 + emp.overtime;
} //end of class 2
else if(data[i].classification == 3) {
emp.overtime = (data[i].hours_worked - 40) * (6.30 *1.5);
emp.gross_salary = data[i].hours_worked *6.30 + emp.overtime;
} //end of class 3
else if (data[i].classification == 4) {
emp.overtime = (data[i].hours_worked - 40) *(4.65 * 1.5);
emp.gross_salary = data[i].hours_worked *4.65 + emp.overtime;
} //end of class 4
} //end of overtime else loop
if(emp.gross_salary <= 200){
emp.net_salary = emp.gross_salary -(emp.gross_salary * .12);
} // tax rate for 12%
else if(emp.gross_salary > 200 || emp.gross_salary <=350){
emp.net_salary = emp.gross_salary - (emp.gross_salary * .15) ;
} //tax rate for 15%
else if (emp.gross_salary > 350){
emp.net_salary = emp.gross_salary -(emp.gross_salary * .18);
}
printf("Name : %s | Age : %i | Classificatin : %i | Hours Worked :%i | Gross Salary : $%.2f | Net Salary : $%.2f \n", data[i].name, data[i].age, data[i].classification, data[i].hours_worked, emp.gross_salary, emp.net_salary);
data[i] = descend_order(data[i]);
printf("Name : %s | Age : %i | Classificatin : %i | Hours Worked :%i | Gross Salary : $%.2f | Net Salary : $%.2f \n", data[i].name, data[i].age, data[i].classification, data[i].hours_worked, emp.gross_salary, emp.net_salary);
} //end of for loop
return 0;
}