keep getting errortrying read from a file and send data to a file

Im reading in an array of struct from a file and sorting by order date then calculating the sale amount for each item (quantity*price) then calling a max function to get the max value and sending the data to a report file

these are the error
Error 1 error LNK2019: unresolved external symbol "double __cdecl getMax(struct transaction * const,int)" (?getMax@@YANQAUtransaction@@H@Z) referenced in function _main

Error 2 error LNK1120: 1 unresolved externals 1

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
 # include<iostream>
# include <string>
# include <fstream>
using namespace std;

struct transaction
{
	string salesPersonID, item1ID, item2ID, item3ID, item4ID, orderDate, contactEmail;
	int item1Quantity, item2Quantity, item3Quantity, item4Quantity;
	double item1Price, item2Price, item3Price, item4Price, item1amount, item2amount, item3amount, item4amount,calculateField;

};
void swap(transaction A[], int i, int j); 
void sort(transaction A[], int size); 
double getMax (transaction A[], int size);
double calc(int quantity, double price);

int main()
{
	int count=0 ;//set counter
	transaction data[1000];// read file into array
	fstream getInfo;
	getInfo.open ("data.txt");
	fstream putInfo;
	putInfo.open("report.txt");
	getInfo >> data[count].salesPersonID >> data[count].item1ID >>data[count].item1Quantity>>data[count].item1Price>>data[count].item2ID>>data[count].item2Quantity>>data[count].item2Price>>data[count].item3ID>>data[count].item3Quantity>>data[count].item3Price>> data[count].item4ID >>data[count].item4Quantity>>data[count].item4Price>>data[count].orderDate>>data[count].contactEmail;
//
	while (!getInfo.eof())
	{
		count++;
		getInfo >> data[count].salesPersonID >> data[count].item1ID >>data[count].item1Quantity>>data[count].item1Price>>data[count].item2ID>>data[count].item2Quantity>>data[count].item2Price>>data[count].item3ID>>data[count].item3Quantity>>data[count].item3Price>> data[count].item4ID >>data[count].item4Quantity>>data[count].item4Price>>data[count].orderDate>>data[count].contactEmail;
		//
		data[count].item1amount = calc(data[count].item1Quantity, data[count].item1Price);
		data[count].item2amount = calc(data[count].item2Quantity, data[count].item2Price);
		data[count].item3amount = calc(data[count].item3Quantity, data[count].item3Price);
		data[count].item4amount = calc(data[count].item4Quantity, data[count].item4Price);

		data[count].calculateField=getMax(data, count);
		if( count>0);
		sort(data,count);
		for (int i=0; i<count; i++)
		{
			putInfo<<"ON the given order date"<<data[i].orderDate<<"the maximum revenue came from"<<data[count].calculateField;
		}
	}
	getInfo.close();
	putInfo.close();
	return 0; 

} 

void swap(transaction A[], int i, int j) 
{ 
	transaction temp = A[i]; 
	A[i] = A[j]; 
	A[j] = temp; 
	return; 
} 
//
void sort(transaction A[], int size) 
{ 
	for (int p = 1; p < size; p++) 
		for (int c = 0; c < size - p; c++) 
			if (A[c].orderDate > A[c + 1].orderDate) swap(A, c, c + 1); 
	return; 
}
//
double calc(int quantity, double price)
{
	double amount = quantity * price;
	return amount;
}
//  max function
double getMax (int arr[], int size)
{
	 
	double high= arr[0];
	for ( int r=1; r<size; r++)
	{
		if(arr[r]>high)
		{
			high=arr[r];
		}
	}
	return high;
}
Last edited on
http://www.cplusplus.com/forum/articles/40071/#msg216270
In general compiler errors indicate the culprit line, you may want to look at that.

Also http://www.cplusplus.com/forum/general/113904/#msg622050


Another thing, you say `keep getting error C4390 when inputting a file' that makes to believe that it is a runtime error (e.g. a crash), or the throwing of an exception.
However http://msdn.microsoft.com/en-us/library/8f1zx4y1.aspx indicates a compiler warning.
Last edited on
Topic archived. No new replies allowed.