help! C2447: '{' : missing function header (old-style formal list?)

I am not sure what the problem is. Any help would be appreciated. I got error C2447: '{' : missing function header (old-style formal list?)

#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

const int ROW = 4;
const int COL = 5;
void displayArray1(string [][COL], int [][COL], int ROW, int COL);
int main()
{



string seatingChart[ROW][COL] = {
{"Joe", "Moe", "Curly", "Diana", "Beth"},
{"Ben", "Bart", "Deb", "Nick", "Harry"},
{"Kaitland", "Matt", "Tom", "Sean", "June"},
{"Jean", "Sarah", "Sara", "Elizabeth", "Jessica"}
};

int grades[ROW][COL] = {
{99, 55, 45, 77, 67},
{98, 78, 88, 78, 88},
{72, 76, 99, 76, 86},
{89, 77, 97, 88, 75}
};


cout << setw(34) << right << "(front of room)\n";
cout << "----------------------------------------------------------------------";
cout << setw(33) << right << "Seating Chart\n" << endl << endl;

displayArray1(seatingChart, grades, ROW, COL);

cin.get();
return 0;
}
error points here --->{
void displayArray1(string [][COL], int [][COL], int ROW, int COL);

for(int i = 0; i < ROW; i++)
{
for(int j = 0; j < COL; j++)
{
cout << setw(15) << left << seatingChart[i][j];
cout << setw(15) << left << "(" << grades[i][j] << ")";
}
}
}


Thank you
Please, use the code tags and informative indentation. See http://www.cplusplus.com/articles/jEywvCM9/

You probably do use an IDE and the editor of the IDE hopefully has some syntax highlighting and auto-formatting functions. Use them.

Your code in tags, with some whitespace changed:
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
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

const int ROW = 4;
const int COL = 5;

void displayArray1(string [][COL], int [][COL], int ROW, int COL);

int main()
{
  string seatingChart[ROW][COL] = {
    {"Joe", "Moe", "Curly", "Diana", "Beth"},
    {"Ben", "Bart", "Deb", "Nick", "Harry"},
    {"Kaitland", "Matt", "Tom", "Sean", "June"},
    {"Jean", "Sarah", "Sara", "Elizabeth", "Jessica"}
  };

  int grades[ROW][COL] = {
    {99, 55, 45, 77, 67},
    {98, 78, 88, 78, 88},
    {72, 76, 99, 76, 86},
    {89, 77, 97, 88, 75}
  };

  cout << setw(34) << right << "(front of room)\n";
  cout << "----------------------------------------------------------------------";
  cout << setw(33) << right << "Seating Chart\n" << endl << endl;

  displayArray1(seatingChart, grades, ROW, COL);

  cin.get();
  return 0;
}


{ // <-- error points here

  void displayArray1(string [][COL], int [][COL], int ROW, int COL);

  for(int i = 0; i < ROW; i++)
  {
    for(int j = 0; j < COL; j++)
    {
      cout << setw(15) << left << seatingChart[i][j];
      cout << setw(15) << left << "(" << grades[i][j] << ")";
    }
  }
}


Does anything in that look odd to you?
No not exactly.
1
2
3
4
5
6
7
8
9
10
11
12
13
{ // <-- error points here

  void displayArray1(string [][COL], int [][COL], int ROW, int COL);

  for(int i = 0; i < ROW; i++)
  {
    for(int j = 0; j < COL; j++)
    {
      cout << setw(15) << left << seatingChart[i][j];
      cout << setw(15) << left << "(" << grades[i][j] << ")";
    }
  }
}


Your problem is in the above bit, not just where the error reports... You have a semi colon at the end of this line...

void displayArray1(string [][COL], int [][COL], int ROW, int COL);

Which shouldn't be there and it should look more like this....

1
2
3
4
5
6
7
8
9
10
11
12

 void displayArray1(string [][COL], int [][COL], int ROW, int COL)
{
  for(int i = 0; i < ROW; i++)
  {
    for(int j = 0; j < COL; j++)
    {
      cout << setw(15) << left << seatingChart[i][j];
      cout << setw(15) << left << "(" << grades[i][j] << ")";
    }
  }
}


That should fix you :)
1>c:\users\u245564\desktop\u11_studentexercise01.cpp(140): error C2065: 'seatingChart' : undeclared identifier
1>c:\users\u245564\desktop\u11_studentexercise01.cpp(141): error C2065: 'grades' : undeclared identifier

Now I am getting these 2 errors
Your function takes two array arguments. What are their names?
seatingChart and grades.

I looked online about what this error means and it says to add a "std::" in front of cout which does not work for me and has made me more confused lol.
seatingChart and grades

Hmmm,
1
2
3
4
5
void displayArray1( string   [][COL], int   [][COL], int ROW, int COL )
//                         ^              ^              ^        ^
{
  // function body
}

Four arguments. The third has name "ROW" and the fourth has name "COL", but the first and second have no name.


Note. It is ok to declare function (as in line 10) without argument names.
void displayArray1( string [][COL], int [][COL], int, int );
The calling code does not care about the names. However, the declarations are usually what the programmer looks at when deciding what to call, so having names there is good style.

Another note: there is still "COL" in this nameless declaration. That is not a name for a (new) variable. That dereferences a variable to place a value within the brackets.

That leads to yet another note:
1
2
const int COL = 5;
void displayArray1( int [][COL], int COL);

The COL on line 1 is the name of a constant global variable.
The first COL on line 2 sets the size of array dimension to be 5, because the name "COL" refers to variable that was defined on line 1.

The second COL on line 3 has nothing to do with the global variable. Its an entirely different variable that simply happens to have same name as the global variable. Within this function, the "COL" means the argument of the function, not the global value 5. The name from outer scope is masked by name from local scope. That is bad style.
Topic archived. No new replies allowed.