Print out issue with payroll program

I'm a beginner in C++. I have a payroll program that is compiled without error. However, the only output I get is the header information on my report. I'm not sure if the problem is with my input or output sections. The input file is straightforward and a format I've used before. The code is outlined below. I would appreciate any tips on where my errors lie.

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

//Function Prototypes
int readalldata(char[],char[],char[],int[],int[],float[],const int);
int n;
void findovertimehours(int[],int[],int);
void findovertimepay(int[],float[],float[],int);
void findregularhours(int[],int[],int);
void findregularpay(int[],float[],float[],int);
void findgrosspay(float[],float[],float[],int);
void findtaxrate(float[],float[],int);
void findtaxamount(float[],float[],float[],int);
void findnetpay(float[],float[],float[],int);
void printalldata(char[],char[],char[],int[],int[],float[],int[],float[],float[]
,float[],float[],float[],int);


int main(void){
const int MAXSIZE=100;

//Declaration of Variables
int n;
char fname[MAXSIZE][10],lname[MAXSIZE][15],maritalstatus[MAXSIZE][1];
int employeessn[MAXSIZE];int hoursworked[MAXSIZE];
int regularhours[MAXSIZE];int overtimehours[MAXSIZE];
float hourlyrate[MAXSIZE];float regularpay[MAXSIZE];
float overtimepay[MAXSIZE];float grosspay[MAXSIZE];
float taxrate[MAXSIZE];float taxamount[MAXSIZE];float netpay[MAXSIZE];

//Function Calls
n=readalldata(fname[10],lname[15],maritalstatus[1],employeessn,
hoursworked,hourlyrate,MAXSIZE);
findovertimehours(hoursworked,overtimehours,n);
findovertimepay(overtimehours,hourlyrate,overtimepay,n);
findregularhours(hoursworked,regularhours,n);
findregularpay(regularhours,regularpay,hourlyrate,n);
findgrosspay(regularpay,overtimepay,grosspay,n);
findtaxrate(grosspay,taxrate,n);
findtaxamount(grosspay,taxrate,taxamount,n);
findnetpay(grosspay,taxamount,netpay,n);
printalldata(fname[10],lname[15],maritalstatus[1],employeessn,
hoursworked,hourlyrate,overtimehours,overtimepay,regularpay,
grosspay,taxamount,netpay,n);
system("pause");
return 0;
}//MAIN

//Function Definitions

int readalldata(char fname[],char lname[],char maritalstatus[],int
employeessn[],int hoursworked[],float hourlyrate[],int n){
ifstream fin("payrollinfo.txt");
n=0;
while(fin>>fname[n]>>lname[n]>>maritalstatus[n]>>employeessn[n]>>
hoursworked[n]>>hourlyrate[n])n+1;
fin.close();
return n;
}//READALLDATA

void findovertimehours(int hoursworked[],int overtimehours[],int n){
for(int i=0;i<n;i+1){
if(hoursworked[i]>40)overtimehours[i]=hoursworked[i]-40;
else overtimehours[i]=0;
}//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[],float hourlyrate[],float overtimepay[],
int n){
for(int i=0;i<n;i+1){
overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
}
}

void findregularhours(int hoursworked[],int regularhours[],int n){
for(int i=0;i<n;i+1){
if(hoursworked[i]>40)regularhours[i]=40;
else regularhours[i]=hoursworked[i];
}//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[],float regularpay[],float hourlyrate[],
int n){
for(int i=0;i<n;i+1){
regularpay[i]=regularhours[i]*hourlyrate[i];
}//FOR
}//FINDREGULARPAY

void findgrosspay(float regularpay[],float overtimepay[],float grosspay[],
int n){
for(int i=0;i<n;i+1){
grosspay[i]=overtimepay[i]+regularpay[i];
}//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[],float taxrate[],int n){
for(int i=0;i<n;i+1){
if(grosspay[i]>1000)taxrate[i]=0.30;
else if(grosspay[i]>800)taxrate[i]=0.20;
else if(grosspay[i]>500)taxrate[i]=0.10;
else taxrate[i]=0.00;
}//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[],float taxamount[],float taxrate[],int n){
for(int i=0;i<n;i+1){
taxamount[i]=grosspay[i]*taxamount[i];
}//FOR
}//FINDTAXRATE

void findnetpay(float grosspay[],float taxamount[],float netpay[],int n){
for(int i=0;i<n;i+1){
netpay[i]=grosspay[i]-taxamount[i];
}//FOR
}//FINDNETPAY

void printalldata(char fname[],char lname[],char maritalstatus[],
int employeessn[],int hoursworked[],float hourlyrate[],int overtimehours[],
float overtimepay[],float regularpay[],float grosspay[],float taxamount[],
float netpay[],int n){
cout<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(15)<<"STAT"<<setw(15)
<<"SSN"<<setw(15)<<"HW"<<setw(15)<<"HR"<<setw(15)<<"OTH"<<
setw(15)<<"OTP"<<setw(15)<<"REGP"<<setw(15)<<"GROSS"<<setw(15)
<<"TAX"<<setw(15)<<"NET PAY"<<endl;
for(int i=0;i<n;i+1){
cout<<fname[i]<<setw(15)<<lname[i]<<setw(15)<<
maritalstatus[i]<<setw(15)<<employeessn[i]<<setw(15)<<
hoursworked[i]<<setw(15)<<hourlyrate[i]<<setw(15)<<
overtimehours[i]<<setw(15)<<overtimepay[i]<<setw(15)<<
regularpay[i]<<setw(15)<<grosspay[i]<<setw(15)<<
taxamount[i]<<setw(15)<<netpay[i]<<endl;
}//FOR
}//PRINTALLDATA
Last edited on
Please use code tags and layout your program properly...

[ code ]
// code goes here
[/ code ] (use the tags without the spaces)
I went back and cleaned up the program based on your comments or at least how I understood them. I edited my original program with the code tags. Does this help?
try testing the readalldata function to see if it is actually pulling the data from the file with a cout right after the function call?
No I meant for posting on the forum e.g. :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;

//Function Prototypes
int readalldata(char[],char[],char[],int[],int[],float[],const int);
int n;
void findovertimehours(int[],int[],int);
void findovertimepay(int[],float[],float[],int);
void findregularhours(int[],int[],int);
void findregularpay(int[],float[],float[],int);
void findgrosspay(float[],float[],float[],int);
void findtaxrate(float[],float[],int);
void findtaxamount(float[],float[],float[],int);
void findnetpay(float[],float[],float[],int);
void printalldata(char[],char[],char[],int[],int[],float[],int[],float[],float[]
,float[],float[],float[],int);


int main(void){
const int MAXSIZE=100;

//Declaration of Variables
int n;
char fname[MAXSIZE][10],lname[MAXSIZE][15],maritalstatus[MAXSIZE][1];
int employeessn[MAXSIZE];int hoursworked[MAXSIZE];
int regularhours[MAXSIZE];int overtimehours[MAXSIZE];
float hourlyrate[MAXSIZE];float regularpay[MAXSIZE];
float overtimepay[MAXSIZE];float grosspay[MAXSIZE];
float taxrate[MAXSIZE];float taxamount[MAXSIZE];float netpay[MAXSIZE];

//Function Calls
n=readalldata(fname[10],lname[15],maritalstatus[1],employeessn,
hoursworked,hourlyrate,MAXSIZE);
findovertimehours(hoursworked,overtimehours,n);
findovertimepay(overtimehours,hourlyrate,overtimepay,n);
findregularhours(hoursworked,regularhours,n);
findregularpay(regularhours,regularpay,hourlyrate,n);
findgrosspay(regularpay,overtimepay,grosspay,n);
findtaxrate(grosspay,taxrate,n);
findtaxamount(grosspay,taxrate,taxamount,n);
findnetpay(grosspay,taxamount,netpay,n);
printalldata(fname[10],lname[15],maritalstatus[1],employeessn,
hoursworked,hourlyrate,overtimehours,overtimepay,regularpay,
grosspay,taxamount,netpay,n);
system("pause");
return 0;
}//MAIN 

//Function Definitions

int readalldata(char fname[],char lname[],char maritalstatus[],int 
employeessn[],int hoursworked[],float hourlyrate[],int n){
ifstream fin("payrollinfo.txt");
n=0;
while(fin>>fname[n]>>lname[n]>>maritalstatus[n]>>employeessn[n]>>
hoursworked[n]>>hourlyrate[n])n+1;
fin.close();
return n;
}//READALLDATA

void findovertimehours(int hoursworked[],int overtimehours[],int n){
for(int i=0;i<n;i+1){
if(hoursworked[i]>40)overtimehours[i]=hoursworked[i]-40;
else overtimehours[i]=0;
}//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[],float hourlyrate[],float overtimepay[],
int n){
for(int i=0;i<n;i+1){
overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
}
}

void findregularhours(int hoursworked[],int regularhours[],int n){
for(int i=0;i<n;i+1){
if(hoursworked[i]>40)regularhours[i]=40;
else regularhours[i]=hoursworked[i];
}//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[],float regularpay[],float hourlyrate[],
int n){
for(int i=0;i<n;i+1){
regularpay[i]=regularhours[i]*hourlyrate[i];
}//FOR
}//FINDREGULARPAY

void findgrosspay(float regularpay[],float overtimepay[],float grosspay[],
int n){
for(int i=0;i<n;i+1){
grosspay[i]=overtimepay[i]+regularpay[i];
}//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[],float taxrate[],int n){
for(int i=0;i<n;i+1){
if(grosspay[i]>1000)taxrate[i]=0.30;
else if(grosspay[i]>800)taxrate[i]=0.20;
else if(grosspay[i]>500)taxrate[i]=0.10;
else taxrate[i]=0.00;
}//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[],float taxamount[],float taxrate[],int n){
for(int i=0;i<n;i+1){
taxamount[i]=grosspay[i]*taxamount[i];
}//FOR
}//FINDTAXRATE

void findnetpay(float grosspay[],float taxamount[],float netpay[],int n){
for(int i=0;i<n;i+1){
netpay[i]=grosspay[i]-taxamount[i];
}//FOR
}//FINDNETPAY

void printalldata(char fname[],char lname[],char maritalstatus[],
int employeessn[],int hoursworked[],float hourlyrate[],int overtimehours[],
float overtimepay[],float regularpay[],float grosspay[],float taxamount[],
float netpay[],int n){
cout<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(15)<<"STAT"<<setw(15)
<<"SSN"<<setw(15)<<"HW"<<setw(15)<<"HR"<<setw(15)<<"OTH"<<
setw(15)<<"OTP"<<setw(15)<<"REGP"<<setw(15)<<"GROSS"<<setw(15)
<<"TAX"<<setw(15)<<"NET PAY"<<endl;
for(int i=0;i<n;i+1){
cout<<fname[i]<<setw(15)<<lname[i]<<setw(15)<<
maritalstatus[i]<<setw(15)<<employeessn[i]<<setw(15)<<
hoursworked[i]<<setw(15)<<hourlyrate[i]<<setw(15)<<
overtimehours[i]<<setw(15)<<overtimepay[i]<<setw(15)<<
regularpay[i]<<setw(15)<<grosspay[i]<<setw(15)<<
taxamount[i]<<setw(15)<<netpay[i]<<endl;
}//FOR
}//PRINTALLDATA 


And the "layout your program properly" I was referring to was the indentations when posting because as you can see, the above doesn't have.
I tried a cout right after the function call to readdata using just the fields I was inputting. The results on the screen came back with a series of characters like webdings followed by two seven-digit numbers.
Why are you using a value returning function to read all the data anyway? why not use a void function with referecnce parameters? and why read input 1 character at a time with char type? seems more complicated than it needs to be.
I did make the change to string values instead of characters. I did get a response on my cout routine right after the readdata function. It gave me one line apparently of memory addresses. At least that's a step in the right direction.
Topic archived. No new replies allowed.