LNK 2019 on program functions

Hi.
Just to start, I know what the LNK 2019 error means, but cannot find the source anywhere. I know the error log reports that its in the functions, so maybe one of the arguments is the wrong type. I suspect it has something to do with the inventory structure argument in the function, but I'm not sure. If anyone would take a look at it, I would appreciate it. I have a feeling it's gonna be one of those "Duh" moments for me.

Here is the error log:
1>file2.obj : error LNK2019: unresolved external symbol "void __cdecl SALES::showSales(struct SALES::Sales const &)" (?showSales@SALES@@YAXABUSales@1@@Z) referenced in function _main
1>file2.obj : error LNK2019: unresolved external symbol "void __cdecl SALES::setSales(struct SALES::Sales &)" (?setSales@SALES@@YAXAAUSales@1@@Z) referenced in function _main
1>file2.obj : error LNK2019: unresolved external symbol "void __cdecl SALES::setSales(struct SALES::Sales &,double const * const,int)" (?setSales@SALES@@YAXAAUSales@1@QBNH@Z) referenced in function _main

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
// Sales.h
#ifndef SALES_H_
#define SALES_H_
 
namespace SALES
{
	const int QUARTERS = 4;
	struct Sales
	{
		double sales[QUARTERS];
		double average;
		double max;
		double min;
	};
	// copies the lesser of 4 or n items from the array ar
	// to the sales member of s and computes and stores the
	// average, maximum, and minimum values of the entered items;
	// remaining elements of sales, if any, set to 0
	void setSales(Sales & s, const double ar[], int n);
	// gathers sales for 4 quarters interactively, stores them
	// in the sales member of s and computes and stores the
	// average, maximum, and minumum values
	void setSales(Sales & s);
	// display all information in structure s
	void showSales(const Sales & s);
}
#endif


// Program 9.4file1.cpp
#include<iostream>
#include "Sales.h"
using namespace SALES;

void setSales(Sales & s, const double ar[], int n)
{
	using std::cout;
	using std::cin;
	double total = 0;
	for (int i = 0; i < n; i++)
	{
		s.sales[i] = ar[i];
		total += s.sales[i];
	}
	s.average = total/QUARTERS;
	s.max = s.sales[0];
	s.min= s.sales[0];
	for (int i = 0; i < n; i++) //calculate max
	{
		if (s.sales[i] > s.max)
			s.sales[i] = s.max;
		else if (s.sales[i] < s.min)
			s.sales[i] = s.min;
	}
}

void setSales(Sales & s)
{
	using std::cout;
	using std::cin;
	double total = 0;
	cout << "Please enter the sales for the approrpiate quarter.\n";
	// input the sales
	for (int i = 0; i < QUARTERS; i++) 
	{
	cout << "Please enter quarter " << i + 1 << "sales: ";
	cin >> s.sales[i];
	total += s.sales[i];
	}
	s.average = total/QUARTERS;
	s.max = s.sales[0];
	s.min= s.sales[0];
	//calculate max and min
	for (int i = 0; i < QUARTERS; i++)
	{
		if (s.sales[i] > s.max)
			s.sales[i] = s.max;
		else if (s.sales[i] < s.min)
			s.sales[i] = s.min;
	}
}

void showSales(const Sales & s)
{
	using std::cout;
	for (int i = 0; i < QUARTERS; i++)
		cout << s.sales[i] << "\n";
	cout << "The average is: " << s.average << "\n";
	cout << "The max is: " << s.max << "\n";
	cout << "The min is: " << s.min << "\n";
}


// Program 9.4file2.cpp
#include<iostream>
#include "Sales.h"

int main()
{
	using namespace SALES;
	using std::cout;
	using std::cin;
	Sales inventory[2];
	double ar[3] = {5.0, 9.0, 6.0};
	cout << "Welcome to the inventory tracking database.\n";
	setSales(inventory[1], ar, 3);
	cout << "Please enter last year's quarterly sales.\n";
	setSales(inventory[2]);
	cout << "Here is this year's sales: \n";
	showSales(inventory[1]);
	cout << "Here is the previous year's sales: \n";
	showSales(inventory[2]);
	return 0;
}
A linker error (LNK...) has to do with files not being correctly linked. Make sure you're linking both Program 9.4file2.cpp and Program 9.4file1.cpp.

Weird names by the way, why not just create seperate folders for each program?
OK. I've checked over the files and to my knowledge, they are properly linked. The program still is giving the error, but I'll try to figure it out. The actual files are named something different, but because it's for a program in a book, I put the Program It's associated with. Thank you for trying to help.
I fixed the error. I had to add the functions to the namespace in Program9.4file1 instead of just putting using namespace SALES. Thanks again.
Topic archived. No new replies allowed.