error E0029 Expected an expression

I keep getting an error message that's saying expected an expression, or error code E0029. I'm new at all this programming stuff, so any advice would be helpful. Here's what i have been working on so far:

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

void displayChart(int visitors[][9], int Visitors);

void displayRecNonRec(int rec_nonRec[][1], int Rec_nonRec);

void displayTentRv(int tent_Rv[][4], int Tent_Rv);

void displayVisitorsPerMonth(int visitorsPerMonth[], int visitors_month);

int main()
{
	int visitors[12][9];
	int Visitors = visitors[12][9];
	displayChart(visitors[][9], Visitors);
}

void displayChart(int visitors[][9], int Visitors)
{
	int visitors_Jan[1];
	int visitors_Feb[2];
	int visitors_Mar[3];
	int visitors_Apr[4];
	int visitors_May[5];
	int visitors_Jun[6];
	int visitors_Jul[7];
	int visitors_Aug[8];
	int visitors_Sep[9];
	int visitors_Oct[10];
	int visitors_Nov[11];
	int visitors_Dec[12];
}

void displayRecNonRec(int rec_nonRec[][1], int Rec_nonRec)
{
}

void displayTentRv(int tent_Rv[][4], int Tent_Rv)
{
}

void displayVisitorsPerMonth(int visitorsPerMonth[], int visitors_month)
{
}

And here's the section where the problem keeps occurring.

int main()
{
	int visitors[12][9];
	int Visitors = visitors[12][9];
	displayChart(visitors[][9], Visitors);
} 
You seem to have your main() function defined twice - once at line 15, and once at line 52.

Also, at lines 18 and 55, visitors[12][9] is past the end of the array. Remember, in C and C++, array indices begin at 0, so visitors[11][8] is the final element of the array.
Last edited on
Lines 49 - 57 are a duplication of main, delete them.

Line 17 creates an uninitialized 2D array, any values contained are garbage values.

Line 18 you are trying to assign an out of bounds value in your 2D array. Arrays are indexed starting at 0 (zero), the end-most element is at [11][8].

Line 19 expects a 2D array as the first parameter.
displayChart(visitors, Visitors);

The displayChart function is creating 12 local 1D arrays. Are you wanting to use the passed 2D array?
The main issue with your code is how it deals with arrays.
I suggest starting small with a simple program, and then building off it.

This declares a 12x9 2D array (for a total of 108 elements).
1
2
3
4
int main()
{
	int visitors[12][9];
}


To pass this to a function, just pass the name.
1
2
3
4
5
6
int main()
{
    int visitors[12][9];
    int other_parameters = 42;
    func(visitors, other_parameters);
}


On the function side, 2D array syntax is kind of weird, but just note that you need to specify the size of the second dimension.
So something like:
1
2
3
4
5
6
7
8
9
10
11
void func(int visitors[][9], int other_parameters)
{
     // ...
}

int main()
{
	int visitors[12][9];
	int other_parameters = 42;
	func(visitors, other_parameters);
}


1
2
	int visitors[12][9];
	int Visitors = visitors[12][9];
This is wrong. There is no need for your 'Visitors' variable. But also, when you declare an array of size [12][9], its actual valid indices you can access range from visitors[0 ... 11][0 ... 8] (the size of each dimension - 1).
By doing int Visitors = visitors[12][9]; you would be going out of bounds of your array.

MikeyBoy I think you typo'd on your last sentence.
Last edited on
MikeyBoy I think you typo'd on your last sentence.

D'oh... thanks! Fixed.
Thank you Mikey that makes sense now. Furry guy, im trying to have the functions set up to where the program can pull the data from the 2d array yes. Thanks Ganado that makes sense, i guess i was trying to declare the first parameter array with the second parameter in my function, to which i now realize i can't do that lol
Im writing this program as an assignment, i have tried everyones advice but im still getting nowhere? Im still getting an error message with the expected an expression displaychart(visitors[][9], Visitors) The first parameter with the array is where im getting the error. It keeps saying to add an expression in the brackets of the Row of the array? But when i put something there, it then says that its incompatible with parameter type? Anyways after working on this again im still coming up with nothing. I'm trying to get this program to take values from a user, and then have those values transferred from functions back to main?
Post your current code so that we can see exactly what you're got now.
Look at your function call:

displaychart(visitors[][9], Visitors)

What is visitors[][9] supposed to mean here? What did you intend that empty array index [] to indicate?

Also, note that that second array index, [9], is still one higher than any valid array index, as several of us have already explained.

Also, the name of your function is displayChart, not displaychart.

Edit: Looking at the definition of displayChart, that first argument is supposed to be the array as a whole. So you should just be using the name of the array as the argument:

displayChart(visitors, Visitors)

And it seems you haven't addressed what Ganado said about the Visitors argument. What is it supposed to be?

Last edited on
Topic archived. No new replies allowed.