Hi, I've been working on a class project to read in an array of structs, process them, then output to a file.
The project reads in the array correctly however, it's not being processed correctly, the output is all zeros. It's prolly something easy but i just can't see what i did wrong. Any help is much appreciated, thanks!
Here's some of the code:
fill array function:
int fillArray(PayRoll[]);
int count;
PayRoll pr[MAX_EMP];
count = fillArray(payRoll);
int
fillArray(PayRoll pr[]){
void openInOutFiles(ifstream&,ofstream&); int count = 0;openInOutFiles(fin,fout);
//opens and checks files char ch; while((ch=fin.peek())!=EOF){
if(isalpha(ch))//bool check, checks to be sure i'm not reading in a chara variable in the wrong spotfin.get(ch);
fin >> pr[count].empNumber>> pr[count].payCode>> pr[count].payRate;
cout << pr[count].empNumber<<" "<< pr[count].payCode<< " "<<pr[count].payRate << endl;
//hourly/salary/piecework inputs if ((pr[count].payCode == 'H') || (pr[count].payCode == 'h')){
fin >> pr[count].hrsWorked;
if (pr[count].hrsWorked > 40){
fin >> pr[count].exempt;
}
}
else if ((pr[count].payCode == 'S') || (pr[count].payCode == 's')){
}
else if ((pr[count].payCode == 'P') || (pr[count].payCode == 'p')){
fin >> pr[count].piecesMade;
}
fin >> pr[count].deductionCode;
cout << pr[count].deductionCode<<endl;
fin.ignore(80,'\n');
//reads in 80 charas or until it hits new line chara, stops after new line, wouldn't work without this for some reasoncount ++;
}
return count;}
Sample of one of the processing functions:
double grossPay(PayRoll& payRoll, double, double, int, double, double); //prototype if ((pr[ i ].payCode == 'H') || (pr[ i ].payCode == 'h')) //function call if hourly{
pr[ i ].grossPay = grossPay(pr[MAX_EMP], pr[ i ].payRate, pr[ i ].hrsWorked, pr[ i ].exempt, regPay, otPay);
}
//hourly worker function definition, should return grossPay for an hourly worker
double
grossPay(PayRoll& pr, double, double, int, double, double){
double regPay = 0; double otPay = 0; if (pr.hrsWorked > 40){
if (pr.exempt == 1){
return (pr.hrsWorked * pr.payRate);}
else{
regPay = pr.hrsWorked * pr.payRate;
otPay = ((pr.hrsWorked - 40) * (pr.payRate / 2));
return (regPay + otPay);}
}
else return (pr.hrsWorked * pr.payRate);}

newb problem processing arrays with functions
Silverback
int fillArray(PayRoll[]);
You don't need to pass this in at all, as it's a member variable.
int count = 0;
this creates a new variable called count, and hides the member variable. Turn it in to count = 0; without the int. Or if you want a local variable, call it something else.