Simple Question

I'm getting an error saying I'm missing { before the left brace. I can't find where that is however. Wherever I put it, I get another error.

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
 
// Can have 2 people play ( x and o)
// or a single person can play the computer
#include <iostream>
#include <iomanip>
using namespace std;

const int N = 3;


void intBoard(char bd[N][N]);
void printBoard(char bd[N][N]);
int mian(void){
	char board[N][N];
	intBoard(board);
	printBoard(board);
	return 0;
}
void intBoard(char bd[N][N]){
	int i, j;
	for (i = 0; i < N; i++)
		for (j = 0; j < N; j++)
			bd[i][j] = ' ';
}
void printBoard(char bd[N][N]){
	// haw many '-' we want per column
	int i, j, k;
	for (i = 0; i < N; i++){
		for (j = 0; j < N; j++)
			cout << "----";
		cout << "-\n";
		for (j = 0; j < N; j++){
			cout << "| " << bd[i][j] << " ";
			cout << "-|\n"; // todo: output the row
		}
		for (j = 0; j < N; j++)
			cout << "----";
		cout << "-\n";
	}
is 'main' having a typo?

it looks like its in the bottom function.
its hard to tell which one because the style you used does not align braces. I won't help you until they align vertically. I know I am in the minority, but you won't have this problem if you code like below, with a comment on each ending brace and vertical alignment:
1
2
3
4
5
6
7
code
{ //on a line by itself
    if (x)
      { // on a line by itself
          stuff
      } //end if x aligned!
} //end 'code'  aligned! 



Printed books need to use
code { //save empty lines and printing costs

Real code isn't printed and empty lines cost 0.
Last edited on
closed account (48T7M4Gy)
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
#include <iostream>
//#include <iomanip> // <-- don't need this ... yet

using namespace std;

const int N = 3;

void intBoard(char bd[N][N]);
void printBoard(char bd[N][N]);

int main(){ //<--
    char board[N][N];
    intBoard(board);
    printBoard(board);
    
    return 0;
}

void intBoard(char bd[N][N]){
    int i, j;
    for (i = 0; i < N; i++)
        for (j = 0; j < N; j++)
            bd[i][j] = ' ';
}

void printBoard(char bd[N][N]){
    // haw many '-' we want per column
    int i, j, k;
    for (i = 0; i < N; i++){
        for (j = 0; j < N; j++)
            cout << "----";
        cout << "-\n";
        
        for (j = 0; j < N; j++){
            cout << "| " << bd[i][j] << " ";
            cout << "-|\n"; // todo: output the row
        }
        
        for (j = 0; j < N; j++)
            cout << "----";
        cout << "-\n";
    }
} // <-- 
Topic archived. No new replies allowed.