prgrm compiles but all I see is the first cout. What am I doing wrong.

I am using dev C++ trying to use functions on this program. I got it to compile with out error but coming up with only the first lind of the output function. I have a feeling it is probably something small that I just for some reason just cant see.
here is the code. Any help would be appreciated.

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

//functions
int readalldata(char[], char[], int[], int[], float[], char[], const int);
void findovthrs(int[], int[], int);
void findotp(int[], float[], float[], int);
void findrgh(int[], int[], int);
void findrgp(int[], float[], float[], int);
void findgp(float[], float[], float[], int);
void findtaxr(float[], float[], char[], int);
void findtax(float[], float[], float[], int);
void findnp(float[], float[], float[], int);
void outputall(char[], char[], int[], int[], float[], char[], int[], float[],
float[], float[], float[], float[], int);

int main(void){
const int MAX=100; //for maximum of 100 employees

//declaration of variables
int n;
int id[MAX], hw[MAX], oth[MAX], rgh[MAX];
float hr[MAX], otp[MAX], rgp[MAX], gp[MAX], tax[MAX],
np[MAX], TAXR[MAX];
char fname[MAX][15], lname[MAX][15], ms[MAX];

//functions calls
n = readalldata( fname[15], lname[15], id, hw, hr, ms, MAX);//
findovthrs(hw, oth, n);
findotp(oth, hr, otp, n);
findrgh(hw, rgh, n);
findrgp(rgh, rgp, hr, n);
findgp(rgp, otp, gp, n);
findtaxr(gp, TAXR, ms, n);
findtax(gp, tax, TAXR, n);
findnp(gp, np, tax, n);
outputall(fname[15], lname[15], id, hw, hr, ms, oth, otp, rgp, gp, tax, np, n);
system("pause");
}//MAIN
// function definitions
int readalldata(char fname[], char lname[], int id[], int hw[], float hr[],
char ms[], int n){
ifstream fin("payrollfunc.txt");
n=0;

while(fin>>fname[n]>>lname[n]>>id[n]>>hw[n]>>hr[n]>>ms[n])n++;

fin.close();
return n;
}//READALLDATA

void findovthrs(int hw[], int oth[], int n){
for(int i=0;i<n;i++){
if(hw[i]>40)oth[i]=hw[i]-40;
else oth[i]=0;
}//FOR
}//FINDOVTHRS

void findotp(int oth[], float hr[], float otp[], int n){
for(int i=0;i<n;i++){
otp[i]=oth[i]*hr[i]*1.5;
}//FOR
}//FINDOTP

void findrgh(int hw[], int rgh[], int n){
for(int i=0;i<n;i++){
if(hw[i]>40)rgh[i]=40;
else rgh[i]=hw[i];
}//FOR
}//FINDRGH

void findrgp(int rgh[], float rgp[], float hr[], int n){
for(int i=0;i<n;i++){
rgp[i]=rgh[i]*hr[i];
}//FOR
}//FINDRGP

void findgp(float rgp[], float otp[], float gp[], int n){
for(int i=0;i<n;i++){
gp[i]=rgp[i]+otp[i];
}//FOR
}//FINDGP

void findtaxr(float gp[], float TAXR[], char ms[], int n){
for(int i=0;i<n;i++){
if ((gp[i]>1000) && ms[i]=='S'||ms[i]=='s') TAXR[i]=0.35;
else if ((gp[i]>1000) && ms[i]=='M'||ms[i]=='m') TAXR[i]=0.30;
else if ((gp[i]>1000) && ms[i]=='H'||ms[i]=='h') TAXR[i]=0.25;
else if ((gp[i]>800) && ms[i]=='S'||ms[i]=='s') TAXR[i]=0.25;
else if ((gp[i]>800) && ms[i]=='M'||ms[i]=='m') TAXR[i]=0.20;
else if ((gp[i]>800) && ms[i]=='H'||ms[i]=='H') TAXR[i]=0.15;
else if ((gp[i]>500) && ms[i]=='S'||ms[i]=='s') TAXR[i]=0.15;
else if ((gp[i]>500) && ms[i]=='M'||ms[i]=='m') TAXR[i]=0.10;
else if ((gp[i]>500) && ms[i]=='H'||ms[i]=='h') TAXR[i]=0.05;
else TAXR[i]=0.0;
}//FOR
}//FINDTAXR

void findtax(float gp[], float tax[], float TAXR[], int n){
for(int i=0;i<n;i++){
tax[i]=gp[i]*TAXR[i];
}//FOR
}//FINDTAX

void findnp(float gp[], float np[], float tax[], int n){
for(int i=0;i<n;i++){
np[i]=gp[i]-tax[i];
}//FOR
}//FINDNP

void outputall(char fname[], char lname[], int id[], int hw[], float hr[],
char ms[], int oth[], float otp[], float rgp[], float gp[], float tax[],
float np[], int n){
cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(7)<<"EMP ID"<<
setw(4)<<"HW"<<setw(6)<<"HR"<<setw(5)<<"STAT"<<setw(5)<<"OTH"<<setw(7)
<<"OTP"<<setw(9)<<"REGP"<<setw(9)<<"GROSS"<<setw(7)<<"TAX"
<< setw(7)<<"NET"<<endl<<endl;
for(int i=0;i<n;i++){
cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname[i]
<<setw(15)<<lname[i]<<setw(7)<<id[i]<<setw(4)<<setprecision(1)<<hw[i]
<<setw(6)<<setprecision(2)<<hr[i]<<setw(5)<<ms[i]<<setw(5)
<<setprecision(1)<<oth[i]<<setw(7)<<setprecision(2)<<otp[i]<<setw(9)
<<rgp[i]<<setw(9)<<gp[i]<<setw(7)<<tax[i]<<setw(7)<<np[i]<<endl;
}//FOR
}//OUTPUTALL
//end
Last edited on
any one please.
I've only had a quick look, but I think it's probably the way you are passing the variable n into your functions. You are passing by copy. The effect of this is that a copy of n is passed into each function and the function manipulates the copy, so when the function returns, the original n is unchanged. So you are not changing the value of n between each function. You need to pass a pointer to nor pass it by reference, in your case the easier change would be to make it by reference.

change the prototypes so that instead of passing int you pass int &

This passes the memory location of n to the function so that it modifies the same variable.

I hope this makes sense
Thank you bnbertha. I tried with no joy could you give me an example please
Hi tdigdug. Im not 100% sure (because i am still learning myself) but I dont think you can directly pass an array as a function argument, you need to use pointers to do so. Check out some tutorials on pointers if you are really keen to get this working.

Also, could you please use the code tags when posting code. They are [c0de][/c0de] (replace 0 with o)
Last edited on
closed account (z05DSL3A)
At the end of your readalldata function output n to see if you are reading the file properly.
Topic archived. No new replies allowed.