Array problem -- error

closed account (2bMo216C)
When I compile this program, I'm getting the error that salesArray is undefined in main(). I am not sure what else to do. this is not a complete program, this is just the beginning. This program is supposed to add all sales total for each month, and print the monthly totals, total sales for the year, best month, worst month. Thanks!

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
/******************
doc box
******************/
#include <iostream>
#include <iomanip>
#include <fstream>

void buildSalesArray (double salesArray[]);
void printSalesArray (double salesArray[]);
void findSum (double salesArray[]);
void findMean (double salesArray[]);
void findLowMonth(double salesArray[]);
void findHighMonth (double salesArray[]);


using namespace std;

#define numMonths 12
const string monthNames[numMonths+1] = {"", "January ", "February ",
"March ", "April ", "May ", "June ", "July ", "August ", "September ", 
"October ", "November ", "December " };

int main ()
{
double salesArray[13] = {0};
buildSalesArray(salesArray);
printSalesArray(salesArray);
findSum(salesArray);
findMean(salesArray);
findHighMonth(salesArray);
findLowMonth(salesArray);

return 0;
}
/*************************************
function doc box
*************************************/
void buildSalesArray(double salesArray[])
{
int monthNumber;
double sales;

ifstream infile;
infile.open ("sales.txt");

if(infile.fail())
	{
	cout <<"sales.txt did not open" << endl;
	exit(1);
	}
		
	infile>>monthNumber;
	while(infile)
	{
	infile >> sales;
	salesArray[monthNumber]+=sales;
	infile>>monthNumber;
	}
}

Last edited on
I get no error when I compile your posted code using Visual Studio.
What compiler are you using?
Please post the EXACT error message you're getting.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
closed account (2bMo216C)
the exact error message I am getting in Quincy is:

in function 'main':
29: undefined reference to 'printSalesArray(double*)'
30: undefined reference to 'findSum(double*)'
31: undefined reference to 'findMean(double*)'
32: undefined reference to 'findHighMonth(double*)'
33: undefined reference to 'findLowMonth(double*)'
collect2: Id returned 1 exit status

Sorry to be difficult but I'm extremely new to programming and don't really know what the code tags do but I will look into it and try to change it.

Thanks!
You're calling functions in main that haven't been defined yet (you just have the function prototypes set up). I'd try commenting out the calls to functions you haven't written yet.
Topic archived. No new replies allowed.