Tic tac toe confusion

Pages: 1... 45678... 13
I did it! It worked!

Alright, what should I do next? : )
Can you do it?
Player X :
Enter row #: 2
Enter column #: 2
* * *
* X *
* * *

> Player O :
Enter row #: 3
Enter column #: 2
* * *
* X *
* O *
Ah, so I just do the same thing but for the other player now?
Yes :)
Can I do it in the same function as the other ones?
> Can I do it in the same function?
Do it this way.
Hint : Copy 'n' Paste
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
52
53
54
55
56
57
58
59
60
61
62
63
64
void userInput(string ticTac[][COLS])
{
    int positionRow;
    int positionCol;

    cout << "Please enter a row and a column player X." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "X";


    printBoard(ticTac);

     cout << "Please enter a row and a column player O." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "O";


    printBoard(ticTac);


    cout << "Please enter a row and a column player X." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "X";


    printBoard(ticTac);

      cout << "Please enter a row and a column player O." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "O";


    printBoard(ticTac);

     cout << "Please enter a row and a column player X." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "X";


      cout << "Please enter a row and a column player O." << endl;

    cin >> positionRow;
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "O";



}


But I feel like I'll lose points for this one if I don't make sure that the user's can't put their "markers" over each other (as in X and O).

Last edited on
You only need a piece of code for the player X, and a piece of code for the player O. If you want to repeat, use a while loop. But we will talk about that later.

Your example is still a failure. Make sure your program output look exactly like this :
Player X :
Enter row #: 2
Enter column #: 2
* * *
* X *
* * *

Player O :
Enter row #: 3
Enter column #: 2
* * *
* X *
* O *
Last edited on
http://prntscr.com/buobae

Hopefully this works.

I'm not too sure what you're asking of me.

I thought I did that already based off of the output given to me, but I suppose not?

It asks players to enter.
They enter row or column.
It shows on board.

Which is what I see you doing.

What am I missing?
Last edited on
Lightshot won't show me the picture.

My advice : Just show your code everytime I need it.
https://s31.postimg.org/lvzaddw6j/Screenshot_46.png

This is the output

(this is a hosting site so it should work)
Ok, I can see the picture.

1
2
3
4
5
cout << "Please enter a row and a column player X." << endl;
    cin >> positionRow;
    cin >> positionCol;
    ticTac[positionRow][positionCol] = "X";
    printBoard(ticTac);


==>
1
2
3
4
5
6
7
8
cout << "Player X : " << endl;
    cout << "Enter row #: ";
    cin >> positionRow;
    cout << "Enter column #: ";   
    cin >> positionCol;

    ticTac[positionRow][positionCol] = "X";
    printBoard(ticTac);


Repeat the same thing for the O player.
And show me your program output.
Never mind. It worked. Compile issues.

Shouldn't I put a way so that one user can't write over the other?
Last edited on
> Shouldn't I put a way so that one user can't write over the other?
Use an if-statement.

1
2
3
4
if(ticTac[positionRow][positionCol] == "*")
// Set the value
else
cout << "That position has been chosen!\n";
Hm, I don't understand that. I mean, I know how to use an if-then statement of course.

But how will that make the user go back and re-enter the value until they choose a spot that's not chosen?

Last edited on
Now you can use while loop.

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
while("X") // Prompt the player X
{
     // Your code
     // If anything fails, display an error message and continue the loop
     if(ticTac[positionRow][positionCol] == "*")
     ticTac[positionRow][positionCol] = "X";
     else 
     {
          cout << "That spot has been already chosen!\n\n";
          continue;
     }
     displayBoard(ticTac);
     break;
}

while("O") // Prompt the player O
{
     // Your code
     // If anything fails, display an error message and continue the loop
     if(ticTac[positionRow][positionCol] == "*")
     ticTac[positionRow][positionCol] = "O";
     else 
     {
          cout << "That spot has been already chosen!\n\n";
          continue;
     }
     displayBoard(ticTac);
     break;
}
Oh I get what you're doing!

"*" means there isn't a O or X on the board, therefore you can put one there.

However, how will the user enter a choice again if they used up a slot already used?
> However, how will the user enter a choice again if they used up a slot already used?
Can you clarify?
Well if they try to put a character over a character that's already there, and it says someone else has put theirs there, how will we prompt them so they enter until they do it correctly?
Pages: 1... 45678... 13