How do i change this to input files or a struct to enter a series of data to the program. I am fine with doing programs asking for input. I get confused on the struct parts. Please help me thru this. It is driving me nuts.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
struct Employee
{
int employeeID, numDependent;
double grossPay, netPay,
cityTax, fedTax,
cityTaxToDate, fedTaxToDate,
grossPayToDate,
payRate, hourWorked;
};
struct Tax
{
double city;
double fed;
};
void calculateTaxes(Tax &, Employee *, int const);
void main()
{
int const numEmployee = 3;
Tax rate;
rate.city = 1.15;
rate.fed = 20;
Employee test[numEmployee];
for(int i=0; i < numEmployee; i++)
{
cout<<"\nEnter employee ID: ";
cin>>test[i].employeeID;
cout<<"Enter the number of dependents: ";
cin>>test[i].numDependent;
cout<<"Enter pay rate: ";
cin>>test[i].payRate;
cout<<"Enter the hours worked: ";
cin>>test[i].hourWorked;
cout<<"Enter city tax withheld to date: ";
cin>>test[i].cityTaxToDate;
cout<<"Enter federal tax withheld to date: ";
cin>>test[i].fedTaxToDate;
cout<<"Enter gross pay to date: ";
cin>>test[i].grossPayToDate;
}
calculateTaxes(rate, test, numEmployee);
cout<<setw(10)<<"\nemployee ID"<<setw(10)<<"gross pay"
<<setw(10)<<"net pay"<<setw(10)<<"city tax"
<<setw(13)<<"federal tax"<<setw(15)<<"total withheld"<<endl;
for(int j=0; j < numEmployee; j++)
{
cout <<setiosflags(ios::fixed | ios::showpoint)<<setprecision(2)
<<setw(10)<<test[j].employeeID<<setw(10)<<test[j].grossPay
<<setw(10)<<test[j].netPay<<setw(10)<<test[j].cityTax
<<setw(13)<<test[j].fedTax
<<setw(15)<<(test[j].cityTaxToDate + test[j].fedTaxToDate)<<endl;
}
}
void calculateTaxes(Tax &t, Employee *e, int const numE)
{
for(int i=0; i < numE; i++)
{
e[i].grossPay = (e[i].payRate)*(e[i].hourWorked);
if(e[i].grossPayToDate < 40000)
e[i].cityTax = (e[i].grossPay)*(t.city/100);
else
e[i].cityTax = 0;
e[i].fedTax = (e[i].grossPay - 50*e[i].numDependent)*(t.fed/100);
e[i].netPay = e[i].grossPay - e[i].cityTax - e[i].fedTax;
e[i].cityTaxToDate = e[i].cityTaxToDate + e[i].cityTax;
e[i].fedTaxToDate = e[i].fedTaxToDate + e[i].fedTax;
e[i].grossPayToDate = e[i].grossPayToDate + e[i].grossPay;
}
}