Payroll Program...no output

Here is a payroll program I wrote for a class (yes, it is a homework assignment). The program compiles with no errors and the debugger seems to show nothing wrong. I don't want the answer. I merely need someone to point me towards why it's outputting exactly nothing. Thanks in advance for any advice.



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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>

using namespace std;

class payroll
{
public:
	int n;
	ifstream fin;
	char empid;//employee id
	char fname;//first name
	char lname;//last name
	char marstat;//marital status character. it's not case-dependent
	char paystat;
	int hwork, rwork, otwork;//quantity of hours in whole numbers
	double hrate, otrate;//rates
	double rpay, grpay, netpay, avgnetpay, otpay;//regular pay, gross pay, net pay, overtime pay
	double minnet (double, int), maxnet (double, int);
	double taxamt;//taxes paid
	double TAXRATE = 0.3;//all tax conditions result in a 30% tax rate
	virtual double calcgrpay();
	virtual double calctax();
	virtual double calcnetpay();
	virtual double calcavgnetpay();
	void printheadings();
	void printdata();
	void pointersort();
	void setAvariables(char &, char &, char &, char &, char &, double &, double &);
	char afname, alname;
	char amarstat;
	int aempid, apaystat, ahwork;
	double ahrate;
	double sum = 0;//declaration of sum variable, initialized to 0
	int counter = 0;//counter for number of employees and their related data
public:
	payroll();//constructor
	~payroll();//destructor
	void printreport();
};//end class payroll

class hourly : public payroll
{
public:double calcgrpay()
{
	if (hwork > 40)
	{
		otwork = (hwork - 40);
		otrate = (hrate * 1.5);
		rpay = hwork * hrate;
		otpay = otwork * otrate;
		grpay = rpay + otpay;
	}//end IF
	else
	{
		grpay = hwork*hrate;
		rpay = grpay;
		otwork = 0;
		otpay = 0;
		
	}//end ELSE
	return 0;
}//end gross pay calculation
};//end class

class salary : public payroll
{
	double hrate=0, otrate=0;
public: double calcgrpay()
{
	if (hwork > 0)
	{
		otpay = hwork * ((rpay / 52) / 40);
		rpay = hrate / 52;
		grpay = rpay + otpay;
		
	}//end IF
	return 0;
}//end GROSS PAY
};//end class

payroll::payroll()
{
	fin.open("employee.txt");//constructor
}
payroll::~payroll()
{
	fin.close();
}

double payroll::calcgrpay()
{
	return 0;
}

double payroll::calctax()
{
	TAXRATE;
	if (marstat == 'S' || marstat == 's' || marstat == 'm' || marstat == 'M' || marstat == 'h' || marstat == 'H')//all conditions result in the same tax rate
	{
		taxamt = grpay * TAXRATE;
		
	}//end of IF loop
	return 0;
}//end of calculations for taxrate

double payroll::calcnetpay()
{
	netpay = (grpay - taxamt);
	sum += netpay;
	return netpay;
}//end of calculations for net pay

double payroll::calcavgnetpay()
{
	avgnetpay = sum / n;
	cout << endl << "The average net pay for " << n << "employees is" << avgnetpay << endl;
	return 0;
}//end calcavgnetpay

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){
	maxnp = 0;
	if(n==0) {maxnp=3000000;}
	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::pointersort(){ 
	//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  

void payroll::setAvariables(char&, char&, char& , char&, char&, double&, double&)
{
	fname = afname;
	lname = alname;
	marstat = amarstat;
	empid = aempid;
	paystat = apaystat;
	hwork = ahwork;
	hrate = ahrate;
}// setAvariables

void payroll::printheadings()
{
	cout << setw(45) << "PAYROLL" << endl;

	cout << "FIRST NAME" << "\t"
		<< "LAST NAME" << "\t"
		<< "EMP ID" << "\t"
		<< "HOURS" << "\t"
		<< "OT HOURS" << "\t"
		<< "RATE" << "\t"
		<< "OT RATE" << "\t"
		<< "OT PAY" << "\t\t"
		<< "GROSSPAY" << "\t"
		<< "TAX PAID" << "\t"
		<< "NET PAY" << "\t" << endl << endl;
}//end of the print headers for data fields

void payroll::printdata()
{
	cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint);
	cout << fname << "\t\t"
		<< lname << "\t\t"
		<< empid << "\t"
		<< hwork << "\t"
		<< otwork << "\t\t"
		<< hrate << "\t"
		<< otrate << "\t"
		<< otpay << "\t\t"
		<< grpay << "\t\t"
		<< taxamt << "\t\t"
		<< netpay << endl;
}//end of print data

void payroll::printreport()
{
	n = 0, sum = 0;
	printheadings();
	fin.open("employee.txt");
	while (fin >> fname >> lname >> empid >> marstat >> hwork >> hrate)
	{
		counter++;
		calcgrpay();
		calctax();
		calcnetpay();
		printdata();
		pointersort();
		n++;
	}//end of WHILE
	avgnetpay = calcavgnetpay();
	cout << "The average net pay for " << n << " employees is $" << avgnetpay << endl;
}//end of print report

int main()
{
	payroll *employee[8], *report = new payroll;
	int i = 0;
	char afname, alname, apaystat, amarstat, aempid;
	double ahwork, ahrate, minnp = 0, maxnp = 0, netpays[18];
	void pointersort(double netpay[], int i);

	ifstream fin;
	fin.open("employee.txt");
	while (fin >> afname >> alname >> apaystat >> amarstat >> aempid >> ahwork >> ahrate)
	{
		if (apaystat == 's')
		{
			employee[i] = new salary();
			employee[i]->setAvariables(afname, alname, apaystat, amarstat, aempid, ahwork, ahrate);
		}
		if (apaystat == 'h')
		{
			employee[i] = new hourly();
			employee[i]->setAvariables(afname, alname, apaystat, amarstat, aempid, ahwork, ahrate);
		}
		employee[i]->calcgrpay();
		employee[i]->calctax();
		netpays[i] = employee[i]->calcnetpay();
		minnp = employee[i]->minnet(minnp, i);
		maxnp = employee[i]->maxnet(maxnp, i);
		report->printheadings();
		employee[i]->printdata();
		i++;
		return 0;
	}
	fin.close();
}//end of main 
Last edited on
@OwlsNSpace

A couple of problems I see at first glance. Line 231. Are you creating a function inside main()? Illegal. Second problem I see, and I think a big one, is line 255. You're canceling the program after reading the first line in 'employee.txt'

I don't know if your program will run correctly after its removal or not, but at least the whole text file will be read in.
1
2
/*char*/ std::string fname; //first name
/*char*/ std::string lname; //last name 
char can only hold 1 character. Use `std::string' for a sentence. (you need to #include <string>
Later you may change the variable name to `first_name' and remove that useless comment.


> Line 231. Are you creating a function inside main()? Illegal.
that's a function declaration. It works the same as if it were outside.
But considering OP's code, it's probably a mistake.

> Second problem I see, and I think a big one, is line 255. You're canceling
> the program after reading the first line in 'employee.txt'
Still, it should output the first line. Well, if the reading was successful.
And perhaps it's also a case of «no output, console closing down»
Topic archived. No new replies allowed.