I have been working on trying to sum the netpays so that I can get an average as well. I think the issue is within the while loop I have created. My cout for the value "sum" just places the last inputed netpay number instead of actually adding all the netpays together. I have this in an array that will only accept two employees for now, I will tweak that part latter. Any help here would be greatly appreiciated!!
Thanks!
while(firstName[A]&&A<2)//less than 2 so that it outputs data after 2 inputs
{
cout<<"Enter First Name:";
cin>>firstName[A];
cout<<"Enter Last Name:";
cin>>lastName[A];
cout<<"Enter S for Single, Enter H for Head of Household, Enter M for Married: ";
cin>>maritalstatus[A];
cout<<"Enter Employee ID:";
cin>>employeeID[A];
cout<<"Enter the Hours Worked:";
cin>>hoursWORKED[A];
cout<<"Enter the Hourly Rate:";
cin>>hourlyRATE[A];
A=A+1;
}// while loop #1 closed
cout<<" TEST PAYROLL INSTITUTE"<<endl;
cout<<"First Name Last Name Status ID RegHrs Rate OT OTPay Gross Tax NET"<<endl;
cout<<"========== ========= ====== ==== ====== ==== ==== ===== ===== === === "<<endl<<endl;
while(netPAY[i]<2); //taking netPay[i] where netPAY[i] gets stored in the array??
{
sum=sum + netPAY[i];
i=i+1;;
}//close loop for sum of all netpays*/
cout<<"Total Netpay is: "<<sum<<endl;
cout<<"Average Netpay is: "<<average<<endl;
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int main(){
cout <<" Creating Array-It is set only to enter 2 employess"<<endl;
int employeeID[2],numberofEMPLOYEES, NUMofEmployees, sum, A, B,i,average;
float hourlyRATE[2], grossPAY, taxAMOUNT,netPAY[2] ;
float TAXRATE;
char maritalstatus[2], firstName[2][10], lastName[2][15];
float overTIME, overTIMEPAY, regularPAY, hoursWORKED[2];
float timePLUSHALF, maritaltax;
regularPAY=0;
overTIMEPAY=0;
overTIME=0;
A=0;
B=0;
i=0;
sum=0;
for(int j=0; j<1; j++) //Use a for loop if you know exactly how many times to loop
{
cout<<"Enter First Name:";
cin>>firstName[j];
cout<<"Enter Last Name:";
cin>>lastName[j];
cout<<"Enter S for Single, Enter H for Head of Household, Enter M for Married: ";
cin>>maritalstatus[j];
cout<<"Enter Employee ID:";
cin>>employeeID[j];
cout<<"Enter the Hours Worked:";
cin>>hoursWORKED[j];
cout<<"Enter the Hourly Rate:";
cin>>hourlyRATE[j];
}
cout<<" TEST PAYROLL INSTITUTE"<<endl<< endl;
for(int j=0; j<1; j++) //You will have decide on a set number of entries or a way to identify the end of the array.
{
grossPAY=hoursWORKED[j]*hourlyRATE[j];
if(hoursWORKED[j]>40)
{
overTIME=hoursWORKED[j]-40;
regularPAY=40*hourlyRATE[j];
timePLUSHALF=hourlyRATE[j]*1.5;
overTIMEPAY=timePLUSHALF*overTIME;
grossPAY=overTIMEPAY+regularPAY;
}
if(grossPAY>1000)
TAXRATE=.30;
elseif(grossPAY>800)
TAXRATE=.20;
elseif (grossPAY>500)
TAXRATE=.10;
elseif(grossPAY<500)
TAXRATE=0;
if(maritalstatus[j]=='S')
maritaltax=TAXRATE*1.05;
elseif(maritalstatus[j]=='H')
maritaltax=TAXRATE*.95;
elseif(maritalstatus[j]=='M')
maritaltax=0;
taxAMOUNT=TAXRATE*grossPAY;
netPAY[j]=grossPAY-taxAMOUNT;
setprecision(2);
cout<<"FIRST NAME " << setiosflags(ios::left)<<setw(11)<<firstName[j]<< endl;
cout<< "LAST NAME " << setiosflags(ios::left)<<setw(10)<<lastName[j]<< endl;
cout<< "M-STATUS " << setiosflags(ios::left)<<setw(7)<<maritalstatus[j]<< endl;
cout<<"ID " << setiosflags(ios::left)<<setw(5)<<employeeID[j]<< endl;
cout<< "TOT-HOURS " << setiosflags(ios::left)<<setw(7)<<hoursWORKED[j]<< endl;
cout<< "HR-RATE " << setiosflags(ios::left)<<setw(5)<<hourlyRATE[j]<< endl;
cout<< "OT " << setiosflags(ios::left)<<setw(5)<<overTIME<< endl;
cout<< "OT-PAY " << setiosflags(ios::left)<<setw(6)<<overTIMEPAY<< endl;
cout<< "GROSS PAY " << setiosflags(ios::left)<<setw(7)<<grossPAY<< endl;
cout<< "TAX AMNT " << setiosflags(ios::left)<<setw(7)<<taxAMOUNT<< endl;
cout<< "NET PAY " << setiosflags(ios::left)<<setw(6)<<netPAY[j]<<endl;
//What is netpay? Gross - Taxes?
cout<<"Total Netpay is: "<< netPAY[j]<<endl;
}//End of for loop
system("PAUSE");
return 0;
}//MAIN
Maybe you don't want for loops if you want any amount of entries. You can change it back easily enough. Either way, do yourself a favor and use more descriptive variables.