Error expected ')' before ',' when trying to create a function

i'm trying to create a function that uses a 2d array but whenever i try to run the program i get the" expected ')' before ','" as well as others only on the function. I've done other functions the exact same way but this one doesn't seem to work.
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
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;

void printElements(int array[][], int length);

int main()
{
    int employSize = 0;

    cout << "How many employees are you entering information?";
    cin >> employSize;

    int employHours[employSize][5];


    for(int i=0; i<=employSize+3; i++)
    {
        for(int j=0; j<=5; j++)
        {
            cout << "/n Enter a the number of hours this/n"
            << "employee worked for this day";

            printElements(employHours, employSize);
            cin >> employHours[i][j];
            system('clr');
        }
    }

    return 0;

}
//*************************************************************************
void printElements(int array[][], int length)
{
    for(int i=1; i<=length; i++)
    {
        cout << i << "| " << "\t";
        for (int j=1; j<=5; j++)
        {
            cout << table[i][j] << "\t";
        }
        cout << "\n";
    }
}


and it gives me the following errors

C:\Users\TUFRob\Documents\EmployeeHours.cpp|28|warning: multi-character character constant [-Wmultichar]|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|7|error: declaration of 'array' as multidimensional array must have bounds for all dimensions except the first|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|7|error: expected ')' before ',' token|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|7|error: expected unqualified-id before 'int'|

C:\Users\TUFRob\Documents\EmployeeHours.cpp||In function 'int main()':|
C:\Users\TUFRob\Documents\EmployeeHours.cpp|28|error: invalid conversion from 'int' to 'const char*' [-fpermissive]|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\stdlib.h|365|error: initializing argument 1 of 'int system(const char*)' [-fpermissive]|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|36|error: declaration of 'array' as multidimensional array must have bounds for all dimensions except the first|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|36|error: expected ')' before ',' token|

C:\Users\TUFRob\Documents\EmployeeHours.cpp|36|error: expected unqualified-id before 'int'|

||=== Build failed: 8 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|

any help would be greatly appreciated
Last edited on
Problem #1:

void printElements(int array[][] /* <- You can't do this*/, int length);

If you're passing a multidimensional array to a function, the size of the inner dimension(s) must be known. Only the outer-most dimension can be unknown.

void printElements(int array[][5] /* <- This would work*/, int length);

Problem #2:

int employHours[employSize][5]; <- you can't do this unless employSize is constant. You don't seem to be getting a related error message though, so your compiler might be allowing it (even if it is nonstandard)


Problem #3:

system('clr');

String literals should be in "double quotes", not 'single quotes'. Since quotes is for character literals.

Problem #4:
cout << table[i][j] << "\t";

'table' was probably supposed to be 'array', since you never created any variable named table.

Problem #5:

1
2
3
for(int j=0; j<=5; j++)
...
for (int j=1; j<=5; j++)


Your loops are ill formed. Remember that array indexes start at 0, not at 1. So if you have an array of size 5... it means that [0], [1], [2], [3], and [4] are the only valid indexes. [5] is an out of bounds index and you must not access it.

For loops are typically constructed like so:

 
for(int j = 0; j < 5; ++j)


Note: starts at 0
Note: uses < instead of <=

Get in the habit of doing both of those. In C/C++ you hardly ever start at 1.
Last edited on
Topic archived. No new replies allowed.