Output not showing

I am trying to run following code with exp.txt input data file that has following data:

101 Allen Ron H S 38.00 15.00 0.00 179.45
200 Will Karr H S 50.00 20.00 0.00 300.50
302 Reba James S S 40.00 21.50 60000.00 250.00
409 Mike King S M 52.00 40.13 30000.00 450.00
109 Mark Jeff S S 34.00 80.30 70000.00 550.40

It's compiling without any error but when run - no output showing. Can anyone tell me what could be wrong?

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class payroll{
ifstream fin;
int n;
public:

char *fname, *lname;
char paystat, maritalstatus, employeeid;
float taxrate;
double hoursworked, overtimehours, regularhours, othr;
double reghourlyrate,regularpay,totalnetpay,minnp,maxnp;
double avgnetpay,taxamount,netpay,grosspay,overtimepay;
virtual double findgrosspay();
//changed the prototype to accept pointers
void setvariables(char*, char*, char, char, char, double, double);
virtual double findtaxamount();
virtual double findnetpay();
virtual double findavgnetpay();
void printheadings();
void printdata();
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
void printreport();
void sortbypointers(void);
payroll();
~payroll();
};

class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked>40){
overtimehours=hoursworked-40;
othr=reghourlyrate*1.5;
regularpay=hoursworked*reghourlyrate;
overtimepay=overtimehours*(reghourlyrate*1.5);
grosspay=regularpay+overtimepay;
}
else{
grosspay=hoursworked*reghourlyrate;
regularpay=grosspay;
overtimehours=0;
overtimepay=0;
return grosspay;
}//IF
};//findgrosspay
};

class salaried: public payroll{
public: double findgrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
};//findgrosspay
};

payroll::payroll(){
fin.open("exp.txt"); }
payroll::~payroll() {
fin.close();}

double payroll::findtaxamount()
{
taxrate=.30;
taxamount=grosspay*taxrate;
return taxamount;
}//findtaxamount

double payroll::findgrosspay()
{
if(hoursworked>0)
{
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
}//findgrosspay


double payroll::findnetpay()
{
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
return netpay;
}//findnetpay

double payroll::findavgnetpay()
{
avgnetpay=totalnetpay/n;
cout<<endl<<"The average net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
return avgnetpay;
}//findavgnetpay

double payroll::minnet(double minnp, int n)
{
if(n==0)
{
minnp=1000000;
}
if(netpay<minnp) {minnp=netpay;}
cout<<endl<<"The minimum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//minnet

double payroll::maxnet(double maxnp, int n)
{
if(n==0) {maxnp=5000000;}
if(netpay>maxnp) {maxnp=netpay;}
cout<<endl<<"The maximum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
return maxnp;
}//maxnp

void payroll:: sortbypointers()
{
cout << "Before sorting by pointer:" << endl;
double p[100];
int i,j;
double temp;
int sortedflag=0;
for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
for(i=0;i<n;i++)cout<< "$" << p[i]<<" ";
while (!sortedflag)
{
sortedflag=1;
for(j=0;j<n-1;j++ )
{
if (p[j]>p[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
sortedflag=0;
}//SWAP
}//J
}//I
cout<<endl<<"SORTED ARRAY:";
for(i=0;i<n;i++)cout<<p[i]<<" ";
}//sortfunction

//changed here to accept char arrays for fname and lname
void payroll::setvariables(char *afname, char *alname, char amaritalstatus, char aemployeeid,
char apaystat, double ahoursworked, double areghourlyrate)
{
fname = afname;
lname = alname;
maritalstatus = amaritalstatus;
employeeid = aemployeeid;
paystat = apaystat;
hoursworked = ahoursworked;
reghourlyrate = areghourlyrate;
}// setvariables

void payroll::printheadings(){
cout<<endl<<setw(15)<<"EMP ID"<<setw(16)<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(8)<<"PAY STAT"<<setw(8)<<"MARITAL STAT"<<setw(8)<<"HW"<<setw(9)<<"RHR"<<setw(9)<<"OTHR"<<setw(9)<<"OTH"<<setw(9)<<"OTP"<<setw(10)<<"REGPAY"<<setw(11)<<"GROSS PAY"<<setw(8)<<"TR"<<setw(9)<<"TA"<<setw(9)<<"NET PAY"<<endl;
cout<<setw(15)<<"==========="<<setw(16)<<"=========="<<setw(15)<<"========="<<setw(8)<<"========"<<setw(8)<<"=="<<setw(8)<<"=="<<setw(9)<<"==="<<setw(9)<<"===="<<setw(9)<<"==="<<setw(9)<<"==="<<setw(10)<<"===="<<setw(11)<<"=="<<setw(8)<<"=="<<setw(9)<<"=="<<setw(9)<<"=="<<endl;
}//PRINTHEADINGS


void payroll::printdata(){
cout<<setw(15)<<employeeid<<setw(16)<<fname<<setw(15)<<lname<<setw(8)<<paystat<<setw(8)<<maritalstatus<<setw(8)<<hoursworked<<setw(9)<<reghourlyrate<<setw(9)<<othr<<setw(9)<<overtimehours<<setw(9)<<overtimepay<<setw(10)<<regularpay<<setw(11)<<grosspay<<setw(8)<<taxrate<<setw(9)<<taxamount<<setw(9)<<netpay
<<endl; }//PRINTDATA
void payroll::printreport()
{
n=0,totalnetpay=0;
printheadings();
fin.open("exp.txt");
while(fin>>employeeid>>fname>>lname>>paystat>>maritalstatus>>hoursworked>>reghourlyrate)
{
   cout<<"in here 1";
findgrosspay();
cout<<"in here 2";
findtaxamount();
cout<<"in here 3";
findnetpay();
printdata();
sortbypointers();
n++;
}//WHILE
avgnetpay=findavgnetpay();
cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<endl;
}//PRINTREPORT

int main(){
payroll *employee[8], *report = new payroll;
//employee[8]->printreport();
int i=0;
char afname[14], alname[16], apaystat, amaritalstatus, aemployeeid;
double ahoursworked, areghourlyrate, minnp,maxnp, netpays[8];
void sortnetpays(double netpays[], int i);

ifstream fin;
fin.open("exp.txt");
while(fin>>aemployeeid>>afname>>alname>>apaystat>>amaritalstatus>>ahoursworked>>areghourlyrate)
{
if(apaystat=='s')
{
employee[i]=new salaried();
employee[i]->setvariables(afname, alname, apaystat, amaritalstatus, aemployeeid, ahoursworked, areghourlyrate);
}//if s
if(apaystat=='h')
{
employee[i]=new hourly();
employee[i]->setvariables(afname, alname, apaystat, amaritalstatus, aemployeeid, ahoursworked, areghourlyrate);

}//if h
employee[i]->findgrosspay();
employee[i]->findtaxamount();
netpays[i]=employee[i]->findnetpay();
minnp = employee[i]->minnet(minnp, i);
maxnp = employee[i]->maxnet(maxnp, i);
report->printheadings();
employee[i]->printdata();

i++;
}//WHILE
fin.close();
//system ("pause");
}//MAIN 
Last edited on
 
101 Allen Ron H S 38.00 15.00 0.00 179.45 


There are 9 fields in this line.

 
while(fin>>aemployeeid>>afname>>alname>>apaystat>>amaritalstatus>>ahoursworked>>areghourlyrate)


Is only trying to read 7 fields. You aren't reading the final 2 numbers. Also, you are testing for 'h' and 's' - whilst the file has 'H' and 'S'. h is not the same as H !
I have changed the input data as follows. Also changed the order of fields in source code, but still output not showing.

101 Allen Ron h s 38.00 20.00
200 Will Karr h s 50.00 30.00
302 Reba James s s 40.00 10.50
409 Mike King s m 52.00 30000.00
109 Mark Jeff s s 34.00 70000.00

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

class payroll{
ifstream fin;
int n;
public:
// first name and last name are char arrays. So made them pointers here
char *fname, *lname;
char employeeid, paystat, maritalstatus ;
float taxrate;
double hoursworked, overtimehours, regularhours, othr;
double reghourlyrate,regularpay,totalnetpay,minnp,maxnp;
double avgnetpay,taxamount,netpay,grosspay,overtimepay;
virtual double findgrosspay();
//changed the prototype to accept pointers
void setvariables(char, char*, char*, char, char,  double, double);
virtual double findtaxamount();
virtual double findnetpay();
virtual double findavgnetpay();
void printheadings();
void printdata();
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
void printreport();
void sortbypointers(void);
payroll();
~payroll();
};

class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked>40){
overtimehours=hoursworked-40;
othr=reghourlyrate*1.5;
regularpay=hoursworked*reghourlyrate;
overtimepay=overtimehours*(reghourlyrate*1.5);
grosspay=regularpay+overtimepay;
}
else{
grosspay=hoursworked*reghourlyrate;
regularpay=grosspay;
overtimehours=0;
overtimepay=0;
return grosspay;
}//IF
};//findgrosspay
};

class salaried: public payroll{
public: double findgrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
};//findgrosspay
};

payroll::payroll(){
fin.open("exp.txt"); }
payroll::~payroll() {
fin.close();}

double payroll::findtaxamount()
{
taxrate=.30;
taxamount=grosspay*taxrate;
return taxamount;
}//findtaxamount

double payroll::findgrosspay()
{
if(hoursworked>0)
{
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
}//findgrosspay


double payroll::findnetpay()
{
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
return netpay;
}//findnetpay

double payroll::findavgnetpay()
{
avgnetpay=totalnetpay/n;
cout<<endl<<"The average net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
return avgnetpay;
}//findavgnetpay

double payroll::minnet(double minnp, int n)
{
if(n==0)
{
minnp=1000000;
}
if(netpay<minnp) {minnp=netpay;}
cout<<endl<<"The minimum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//minnet

double payroll::maxnet(double maxnp, int n)
{
if(n==0) {maxnp=5000000;}
if(netpay>maxnp) {maxnp=netpay;}
cout<<endl<<"The maximum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
return maxnp;
}//maxnp

void payroll:: sortbypointers()
{
cout << "Before sorting by pointer:" << endl;
double p[100];
int i,j;
double temp;
int sortedflag=0;
for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
for(i=0;i<n;i++)cout<< "$" << p[i]<<" ";
while (!sortedflag)
{
sortedflag=1;
for(j=0;j<n-1;j++ )
{
if (p[j]>p[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
sortedflag=0;
}//SWAP
}//J
}//I
cout<<endl<<"SORTED ARRAY:";
for(i=0;i<n;i++)cout<<p[i]<<" ";
}//sortfunction

//changed here to accept char arrays for fname and lname
void payroll::setvariables(char aemployeeid, char *afname, char *alname, char apaystat, char amaritalstatus, double ahoursworked, double areghourlyrate)
{
employeeid = aemployeeid;
fname = afname;
lname = alname;
paystat = apaystat;
maritalstatus = amaritalstatus;
hoursworked = ahoursworked;
reghourlyrate = areghourlyrate;
}// setvariables

void payroll::printheadings(){
cout<<endl<<setw(15)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(8)<<"PAY STAT"<<setw(8)<<"MS"<<setw(8)<<"HW"<<setw(9)<<"RHR"<<setw(9)<<"OTHR"<<setw(9)<<"OTH"<<setw(9)<<"OTP"<<setw(10)<<"REGP"<<setw(11)<<"GP"<<setw(8)<<"TR"<<setw(9)<<"TA"<<setw(9)<<"NP"<<endl;
cout<<setw(15)<<"==========="<<setw(16)<<"=========="<<setw(15)<<"========="<<setw(8)<<"========"<<setw(8)<<"=="<<setw(8)<<"=="<<setw(9)<<"==="<<setw(9)<<"===="<<setw(9)<<"==="<<setw(9)<<"==="<<setw(10)<<"===="<<setw(11)<<"=="<<setw(8)<<"=="<<setw(9)<<"=="<<setw(9)<<"=="<<endl;
}//PRINTHEADINGS


void payroll::printdata(){
cout<<setw(15)<<employeeid<<setw(16)<<fname<<setw(15)<<lname<<setw(8)<<paystat<<setw(8)<<maritalstatus<<setw(8)<<hoursworked<<setw(9)<<reghourlyrate<<setw(9)<<othr<<setw(9)<<overtimehours<<setw(9)<<overtimepay<<setw(10)<<regularpay<<setw(11)<<grosspay<<setw(8)<<taxrate<<setw(9)<<taxamount<<setw(9)<<netpay
<<endl; }//PRINTDATA
void payroll::printreport()
{
n=0,totalnetpay=0;
printheadings();
fin.open("exp.txt");
while(fin>>employeeid>>fname>>lname>>paystat>>maritalstatus>>hoursworked>>reghourlyrate)
{
   cout<<"in here 1";
findgrosspay();
cout<<"in here 2";
findtaxamount();
cout<<"in here 3";
findnetpay();
printdata();
sortbypointers();
n++;
}//WHILE
avgnetpay=findavgnetpay();
cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<endl;
}//PRINTREPORT

int main(){
payroll *employee[8], *report = new payroll;
//employee[8]->printreport();
int i=0;
char aemployeeid, afname[14], alname[16], apaystat, amaritalstatus;
double ahoursworked, areghourlyrate, minnp,maxnp, netpays[8];
void sortnetpays(double netpays[], int i);

ifstream fin;
fin.open("exp.txt");
while(fin>>aemployeeid>>afname>>alname>>apaystat>>amaritalstatus>>ahoursworked>>areghourlyrate)
{
if(apaystat=='s')
{
employee[i]=new salaried();
employee[i]->setvariables(aemployeeid, afname, alname, apaystat, amaritalstatus, ahoursworked, areghourlyrate);
}//if s
if(apaystat=='h')
{
employee[i]=new hourly();
employee[i]->setvariables(aemployeeid, afname, alname, apaystat, amaritalstatus, ahoursworked, areghourlyrate);

}//if h
employee[i]->findgrosspay();
employee[i]->findtaxamount();
netpays[i]=employee[i]->findnetpay();
minnp = employee[i]->minnet(minnp, i);
maxnp = employee[i]->maxnet(maxnp, i);
report->printheadings();
employee[i]->printdata();

i++;
}//WHILE
fin.close();
//system ("pause");
}//MAIN 
Last edited on
Stolen from here or there
https://www.cplusplus.com/forum/beginner/167184/
https://www.cplusplus.com/forum/beginner/2874/

Write your own code, don't try and google your way through this by "finding" code then asking others to fix whatever mess you found/made.
but still output not showing.


Does this code compile without errors? When I compile with VS2019 I get an error at line 18 as fname and lname are type char * - which isn't supported as standard.
@seeplus. It compiles without error. I am using C++ Dev. Type of fname and lname are *char because those are array for pointer.
salem c (2893). Did not know that testing a online code for learning is called "stealing". This code is not only here, but many other places online. As far as I know this forum is for learning - if you do not know answer, then do not spoil other peoples learning with your lecture.
You need to fix a few things:

temp.cpp: In function 'int main()':
temp.cpp:199:51: warning: variable 'netpays' set but not used [-Wunused-but-set-variable]
 double ahoursworked, areghourlyrate, minnp,maxnp, netpays[8];
                                                   ^~~~~~~
temp.cpp: In member function 'virtual double payroll::findgrosspay()':
temp.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
 }//findgrosspay
 ^
temp.cpp: In member function 'virtual double salaried::findgrosspay()':
temp.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
 };//findgrosspay
 ^
temp.cpp: In member function 'virtual double hourly::findgrosspay()':
temp.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 };//findgrosspay


Are you saying that things like employeeid are a single char? char employeeid


Please add indentation and do something about the line length.



Did not know that testing a online code for learning is called "stealing".

Actually, the offence is probably plagiarism.
Last edited on
if you do not know answer, then do not spoil other peoples learning with your lecture.

@salem c knows his stuff, probably writes C++ for a living. Lastchance & seeplus too.
Last edited on
Topic archived. No new replies allowed.