Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this so far, I just need it to also add up and output the total grossPay,

ID: 3532967 • Letter: I

Question

I have this so far, I just need it to also add up and output the total grossPay, fedTax, stateTax, fica, and netPay at the end.




#include<iostream>


using namespace std;

struct employee

{

char empId [10];

double grossPay;

double fedTax;

double stateTax;

double fica;

};


int main()

{

employee e[20];

int n;


cout<<"enter the no of employee ";

cin>>n;


for(int i=0;i<n;i++)

{

cout<<" enter employee no "<<i+1<<" record"<<endl<<endl;

cout<<"employee id :";

cin>>e[i].empId;

cout<<" gross pay :";

cin>>e[i].grossPay;

cout<<" fed tax: ";

cin>>e[i].fedTax;

cout<<" state tax: ";

cin>>e[i].stateTax;

cout<<" fica: ";

cin>>e[i].fica;


cout<<" ";


}

cout<<" employee record with net Pay field ";

for(int i=0;i<n;i++)

{

cout<<"EMP# :"<<e[i].empId<<endl;

cout<<"Gross pay: "<<e[i].grossPay<<endl;

cout<<"Fed tax : "<<e[i].fedTax<<endl;

cout<<"State Tax: "<<e[i].stateTax<<endl;

cout<<"Fica: "<<e[i].fica<<endl;

cout<<"Net pay :"<<e[i].grossPay-e[i].fedTax-e[i].stateTax-e[i].fica<<endl<<endl;


}

return 0;


}

Explanation / Answer

// check this code whether it is fulfiling your requirenments

// if this is not the output you want comment


#include<iostream>


using namespace std;

struct employee

{

char empId [10];

double grossPay;

double fedTax;

double stateTax;

double fica;

};


int main()

{

employee e[20];

int n;


cout<<"enter the no of employee ";

cin>>n;


for(int i=0;i<n;i++)

{

cout<<" enter employee no "<<i+1<<" record"<<endl<<endl;

cout<<"employee id :";

cin>>e[i].empId;

cout<<" gross pay :";

cin>>e[i].grossPay;

cout<<" fed tax: ";

cin>>e[i].fedTax;

cout<<" state tax: ";

cin>>e[i].stateTax;

cout<<" fica: ";

cin>>e[i].fica;


cout<<" ";


}

double totalGrossPay=0;

double totalFedTax=0;

double totalStateTax=0;

double totalFicaTax=0;

double totalNetPay=0;

cout<<" employee record with net Pay field ";

for(int i=0;i<n;i++)

{


cout<<"EMP# :"<<e[i].empId<<endl;

cout<<"Gross pay: "<<e[i].grossPay<<endl;

cout<<"Fed tax : "<<e[i].fedTax<<endl;

cout<<"State Tax: "<<e[i].stateTax<<endl;

cout<<"Fica: "<<e[i].fica<<endl;

cout<<"Net pay :"<<e[i].grossPay-e[i].fedTax-e[i].stateTax-e[i].fica<<endl<<endl;


totalGrossPay=totalGrossPay+e[i].grossPay;

totalFedTax=totalFedTax+e[i].fedTax;

totalStateTax=totalStateTax+e[i].stateTax;

totalFicaTax=totalFicaTax+e[i].fica;

totalNetPay=totalNetPay+e[i].grossPay-e[i].fedTax-e[i].stateTax-e[i].fica;





}


cout<<" total Gross pay= "<< totalGrossPay<<endl;

cout<<" total fed tax= "<<totalFedTax <<endl;

cout<<" total state tax= "<< totalStateTax<<endl;

cout<<" total fica = "<< totalFicaTax<<endl;

cout<<" total net pay= "<< totalNetPay<<endl;


return 0;


}