Payroll with pointer sort

I need help on a homework assignment. I'm trying to sort netpays in this program. I believe I've written the sort properly. It compiles fine except for one error:

fatal error LNK1120: 1 unresolved externals

I cannot figure out how to resolve this error. Please help me.

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
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>

using std::cout;
using std::cin;
using std::setw;
using std::setprecision;
using std::setiosflags;
using std::ios;
using std::endl;
using std::fixed;
using std::left;
using std::string;
using std::ifstream;

//FUNCTION PROTOTYPES
int readalldata(long int[], int[], float[], 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(float[], int n);
int sort(float[], int);

int main(){
	const int MAXSIZE = 100;//FOR MAXIMUM OF 100 EMPLOYEES

	//DECLARATION OF VARIABLES
	int n;
	long int id[MAXSIZE];
	int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
	int regularhours[MAXSIZE];
	float hourlyrate[MAXSIZE], regularpay[MAXSIZE], overtimepay[MAXSIZE], grosspay[MAXSIZE];
	float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];

	//FUNCTION CALLS
	n = readalldata(id, hoursworked, hourlyrate, MAXSIZE);//READ ALL DATA
	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, taxamount, taxrate, n);
	findnetpay(grosspay, netpay, taxamount, n);
	printalldata(netpay, n);
	sort(netpay, n);
	return 0;
}//MAIN
//FUNCTION DEFINITIONS

int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
	ifstream fin("employee.txt");
	n = 0;

	while (fin >> id[n] >> hoursworked[n] >> hourlyrate[n])
		n++;

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

void findovertimehours(int hoursworked[], int overtimehours[], int n){
	for (int i = 0; i<n; i++){
		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++){
		overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
	}//FOR
}//FINDOVERTIMEPAY

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];
	}//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[], float hourlyrate[], int n){
	for (int i = 0; i<n; i++){
		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++){
		grosspay[i] = regularpay[i] + overtimepay[i];
	}//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
	for (int i = 0; i<n; i++){
		if (grosspay[i]>4000.00) taxrate[i] = 0.40;
		else if (grosspay[i]>3000.00) taxrate[i] = 0.30;
		else if (grosspay[i]>1000.00) taxrate[i] = 0.20;
		else taxrate[i] = 0.10;
	}//FOR
}//FINDTAXRATE

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

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

void printalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[], float overtimepay[], float grosspay[], float taxamount[], float netpay[], int n){
	float totalNetPay = 0;

	int i = 0;
	cout << setw(62) << "Payroll" << endl;
	cout << " " << endl << endl;
	cout << "==================================================================== " << endl;
	cout << fixed << setprecision(2);
	cout << "ID" << setw(8)
		<< "FNAME" << setw(8)
		<< "LNAME" << setw(7)
		<< "HOURS" << setw(6)
		<< "RATE" << setw(10)
		<< "OVERPAY" << setw(12)
		<< "GROSSPAY" << setw(5)
		<< "TAX" << setw(11)
		<< "NETPAY" << endl;

	for (i; i<n; i++){
		totalNetPay += netpay[i];
		cout << fixed << left << "" << setw(5)
			<< id[i] << setw(8)
			<< fname[i] << setw(7)
			<< lname[i] << setw(7)
			<< hoursworked[i] << setw(7)
			<< hourlyrate[i] << setw(11)
			<< overtimepay[i] << setw(10)
			<< grosspay[i] << setw(8)
			<< taxamount[i] << setw(8)
			<< netpay[i] << endl;
	}//FOR

	cout << "==================================================================== " << endl;
	cout << "The average netpay for all employees is " << setw(7) << totalNetPay / i << endl;
	cout << endl;
	system("PAUSE");
	cout << endl;
	cout << endl;
}//PRINTALLDATA   FIX THE OUTPUT TO DISPLAY NET PAY ONLY

int sort(float netpay[], int n){
	float *p[100];
	string *f[100];
	string *l[100];

	float *temp;
	string *ftemp;
	string *ltemp;

	int sortedflag = 0;
	int i, j;
	for (i = 0; i < n; i++){
		p[i] = netpay + i;

		while (!sortedflag){
			sortedflag = 1;
			for (j = 0; j < n; j++){
				if (*p[j]>*p[j + 1]){
					temp = p[j];
					ftemp = f[j];
					ltemp = l[j];

					p[j] = p[j + 1];
					f[j] = f[j + 1];
					l[j] = l[j + 1];

					p[j + 1] = temp;
					f[j + 1] = ftemp;
					l[j + 1] = ltemp;
					sortedflag = 0;//SWAP
				}//END J
			}//END I

			cout << endl << "Sorted Array: " << endl;

			for (int i = 0; i < n; i++){
				cout << setw(11) << setprecision(1) << setiosflags(ios::showpoint | ios::fixed | ios::left) << *f[i] << setw(11) << *l[i] << *p[i] << endl;
				cout << "" << endl;
			}
		}
	}
	return 0;
}
fatal error LNK1120: 1 unresolved externals

That is a linker error. That is just a summary, not the actual linker error message.

Compiler creates an object file from each translation unit (~= .cpp). The object file has implementation for some symbols and calls to other symbols. The linker considers multiple object files in order to include implementations for all called symbols in the executable.

The actual error message describes the called symbol for which implementation is not found by the linker. We/you need that information.
Topic archived. No new replies allowed.