[Help!] tic tac toe void function

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void newtable (char board[5][5])
{ 
    for(int n=0;n++;n<5)
     {
             if(n%2==0)
              board[][n]=(' ','|',' ','|',' ');
             else
              board[][n]=('-','-','-','-','-');
     }
     }


void printtable(char array[ ][int n;])
{
     system("CLS");
     for (int n=0;n=n+1;n<5)
     {
         for (m=0,m=m+1,m<w)
             cout<<array[m][n];
             }
             cout<<endl;
             }
  


F:\c++\Tic Tac Toe.cpp In function `void newtable(char (*)[5])':
11 F:\c++\Tic Tac Toe.cpp expected primary-expression before ']' token
13 F:\c++\Tic Tac Toe.cpp expected primary-expression before ']' token
13 F:\c++\Tic Tac Toe.cpp At global scope:
18 F:\c++\Tic Tac Toe.cpp expected primary-expression before "int"
18 F:\c++\Tic Tac Toe.cpp expected `]' before "int"
18 F:\c++\Tic Tac Toe.cpp expected `,' or `...' before "int"
18 F:\c++\Tic Tac Toe.cpp expected `)' before ';' token
18 F:\c++\Tic Tac Toe.cpp expected unqualified-id before ']' token
18 F:\c++\Tic Tac Toe.cpp expected `,' or `;' before ']' token

what am i doing wrong. O_o I'm so confused.
board[][n]=(' ','|',' ','|',' ');You cannot assign arrays like that.
char array[ ][int n;] Also meaningless
board[][n]=(' ','|',' ','|',' ');You cannot assign arrays like that.

but my teacher gave me that
Smack him in the face.
Only place where you can use similar (but not that you have shown) syntax is during initialization
1
2
3
4
5
char board[][5] = {{' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '}}
Will create an array of size 5x5. But it is better to manually declare size: char board[5][5] = //...
Still it is not good idea to store board representation with game logic.
I would use 3x3 array and custom function to print it whatever way you like.
Last edited on
thank you :D
so this is my entire code and its not working right... i dont even know what to say... it just spams random characters and makes noise if that makes any sense :'(

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
#include <iostream> //basic input and output
#include <windows.h> //allows us to change text and background color
using namespace std;




  
int main()
{
    srand (time(NULL)); //makes 5 traps random
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //enables us to change text and background color


    
cout<<"                                  ";
SetConsoleTextAttribute(hConsole, ( BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
cout<<" TIC TAC TOE "<<endl;
SetConsoleTextAttribute(hConsole, (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY));
system("pause");

char board[5][5] = {{' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '}};



     system("CLS");
     for (int n=0;n=n+1;n<5)
     {
         for (int m=0;m=m+1;m<5)
             cout<<board[m][n];
             }
             cout<<endl;



system("pause");
return 0;
}    

for (int n=0;n=n+1;n<5)
It is for(init; condition; expression)
for ( init; condition; update)

Not

for ( init; update; condition )
what do you guys mean? for (int n=0;n<5;n=n+1)?
Last edited on
i tried something different for cout<<board[m][n] but all i get are random numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char board[5][5] = {{' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '}};

system("CLS");
for(int n=0;n<5;n++)
{
    for(int m=0;m<5;m++)
    {
    printf("%d\t",board[n][m]);
    }
    printf("\n");
}
%d is for double output. Search for formatting line which will let you output characters. Or use C++ streams.
do you mean like this?
1
2
3
4
5
6
7
8
9
10
  char board[5][5];   
system("CLS");
for(int n=0;n<5;n++)
{
    for(int m=0;m<5;m++)
    {
    cout<<board[n][m];
    }
    printf("\n");
}
but that still does not work
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    char board[5][5] = {{' ','|',' ','|',' '},
                        {'-','-','-','-','-'},
                        {' ','|',' ','|',' '},
                        {'-','-','-','-','-'},
                        {' ','|',' ','|',' '}};
    for(int n=0;n<5;n++) {
        for(int m=0;m<5;m++) {
            std::cout << board[n][m];
        }
        std::cout << std::endl;
    }
}
 | |
-----
 | |
-----
 | |
Works for me.
thank you so much for that but i still have a problem when i put it into a void function
1
2
3
4
5
6
7
8
9
10
void printboard (void)
{
system("CLS");
    for(int n=0;n<5;n++) {
        for(int m=0;m<5;m++) {
            std::cout << board[n][m];
        }
        std::cout << std::endl;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

void printboard(char board[5][5])
{

    for(int n=0;n<5;n++) {
        for(int m=0;m<5;m++) {
            std::cout << board[n][m];
        }
        std::cout << std::endl;
    }
}

int main()
{
    char board[5][5] = {{' ','|',' ','|',' '},
                        {'-','-','-','-','-'},
                        {' ','|',' ','|',' '},
                        {'-','-','-','-','-'},
                        {' ','|',' ','|',' '}};
    printboard(board);
}
 | |
-----
 | |
-----
 | |
but that gives me this 4 too few arguments to function `void printboard(char (*)[5])'
My code shows this error?
Impossible: http://ideone.com/4Kt9WK
http://ideone.com/MDtAUm line 16 has the problem
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
#include <iostream> 
#include <windows.h>
using namespace std;

void clearboard (void)
{
char board[5][5] = {{' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '}};

}

void printboard(char board[5][5])
{

    for(int n=0;n<5;n++) 
    {
        for(int m=0;m<5;m++) 
        {
            std::cout << board[n][m];
        }
        std::cout << std::endl;
    }
}


  
int main()
{
    srand (time(NULL)); //makes 5 traps random
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //enables us to change text and background color


    
cout<<"                                  ";
SetConsoleTextAttribute(hConsole, ( BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
cout<<" TIC TAC TOE "<<endl;
SetConsoleTextAttribute(hConsole, (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY));
system("pause");

clearboard();
printboard();

system("pause");
return 0;
}    
You are not passing anything to your printboard() function
Pages: 12