Hi, hoping someone can point me on the right road here...
I'm working on a program that reads data from a .in file. The data is for a payroll program (I know...but it's a good start for beginners!). I have everything working as far as the data being read and the functions that calculate the necessary information (netpay, tax rate, etc.). The next step is to have the program also tell me the average dollar amount of the netpays it has calculated. I understand how to sum and average if a user inputs the numbers that are to be worked with but not how to do the same calculations using data that the program has created itself. Basically, I'd like the program to output the statement "The average net pay for this period is: <AvgNetPay>" after the rest of the output. Any help would be much appreciated. My current code is as follows. I'm using Dev C++ for a compiler.
int main(){
const int MAXSIZE=100; //For Maximum of 100 Employees
//Declaration of Variables
int n=0;
int i=0;
char FName[MAXSIZE][10], LName[MAXSIZE][15], mstat[MAXSIZE];
long int id[MAXSIZE];
int hoursworked[MAXSIZE];
float overtimehours[MAXSIZE];
int regularhours[MAXSIZE];
float hourlyrate[MAXSIZE], regularpay[MAXSIZE];
float overtimepay[MAXSIZE], grosspay[MAXSIZE];
float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];
//Function Definitions
int readalldata(char FName[][10], char LName[][15], long int id[], char mstat[], int hoursworked[], float hourlyrate[], int n){
ifstream fin("payroll.in");
n=0;
void findovertimehours(int hoursworked[],float overtimehours[], int n){
for(int i=0; i<n; i++){
if(hoursworked[i]>40)overtimehours[i]=hoursworked[i]-40;
else overtimehours[i]=0;
} // End For
} // End Find Overtime Hours
void findovertimepay(float overtimehours[], float hourlyrate[], float overtimepay[], int n){
for(int i=0; i<n; i++){
overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
} // End For
} // End Find Overtime Pay
void findregularhours(int hoursworked[], int regularhours[], int n){
for(int i=0; i<n; i++){
if(hoursworked[i]>40) regularhours[i]=40;
else regularhours[i]=hoursworked[i];
} // End For
} // End Find Regular Hours
void findregularpay(int regularhours[], float regularpay[], float hourlyrate[], int n){
for(int i=0; i<n; i++){
regularpay[i]=regularhours[i]*hourlyrate[i];
} // End For
} // End Find Regular Pay
void findgrosspay(float regularpay[], float overtimepay[], float grosspay[], int n){
for(int i=0; i<n; i++){
grosspay[i]=regularpay[i]+overtimepay[i];
} // End For
} // End Find Gross Pay
void findtaxrate(float grosspay[], float taxrate[], char mstat[], int n){
for(int i=0; i<n; i++){
if(grosspay[i]>1000.00)taxrate[i]=.30;
else if(grosspay[i]>800.00) taxrate[i]=.20;
else if(grosspay[i]>500.00) taxrate[i]=.10;
else taxrate[i]=0;
if (mstat[i]=='S') taxrate[i]=(taxrate[i]+.05);
else if (mstat[i]=='s') taxrate[i]=(taxrate[i]+.05);
else if (mstat[i]=='H' && grosspay[i]>500) taxrate[i]=(taxrate[i]-.05);
else if (mstat[i]=='h' && grosspay[i]>500) taxrate[i]=(taxrate[i]-.05);
else if (mstat[i]=='M') taxrate[i]=(taxrate[i]*1);
else if (mstat[i]=='m') taxrate[i]=(taxrate[i]*1);
} // End For
} // End Find Tax Rate
void findtaxamount(float grosspay[], float taxamount[], float taxrate[], int n){
for(int i=0; i<n; i++){
taxamount[i]=grosspay[i]*taxrate[i];
} // End For
} // End Find Tax Amount
void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
for(int i=0; i<n; i++){
netpay[i]=grosspay[i]-taxamount[i];
} // End For
} // End Find Net Pay
void printalldata(char FName[][10], char LName[][15], long int id[], char mstat[], int hoursworked[],
float hourlyrate[], float overtimehours[], float overtimepay[], float regularpay[],
float grosspay[], float taxrate[], float netpay[], int n){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//Change Output Text to Green
cout<<"\t \t \t MY PAYROLL PROGRAM"<<endl<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);//Change Output Text back to Grey