[Help!] tic tac toe void function

Pages: 12
what do you mean?
1
2
3
void printboard(char board[5][5]) //Declaring function as accepting one parameter of type char[5][5]
/*...*/
printboard(/*There should be argument here*/);

My code:
printboard(board);//passing 2D array board as argument
can you give me an expample? What do you mean by i dont have an argument
http://www.cplusplus.com/doc/tutorial/functions/

how to call function which require an argument: printboard(board)
How to NOT call it: printboard()
1
2
3
4
5
6
7
8
9
10
11
12
void printboard(char board[ ][5])
{

    for(int n=0;n<5;n++) 
    {
        for(int m=0;m<5;m++) 
        {
            std::cout << board[n][m];
        }
        std::cout << std::endl;
    }
}
printboard(5);isnt that an argument?
i did what you said and i get something wierd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void printboard(char board[5][5])
{
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;
   }
}

printboard(board);

i feel like its much easier to just copy the function every time i need to use it XD
so what am i doing wrong now? im pretty sure this should work but it doesnt
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> //basic input and output
#include <windows.h> //allows us to change text and background color
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

char board[5][5];
    
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(board);

system("pause");
return 0;
} 
im supposed to get this
 | |
-----
 | |
-----
 | |
char board[5][5]; Initialize it. Now you are printing random letters. Your clearboard() function isn't work. I suggest you to read tutorial on functions first.
ok thanks
so i got it down to this
1
2
3
4
5
6
7
8
9
void clearboard (char board[][5])
{
board[5][5] = {{' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '},
                   {'-','-','-','-','-'},
                   {' ','|',' ','|',' '}};

}
everything else works i just dont get this i also call it using this clearboard(board);im pretty sure this should work i just dont get it
Last edited on
Topic archived. No new replies allowed.
Pages: 12