Valid move for Tic Tac Toe

Right now I am really struggling to understand why this is not working. So I have this Tic Tac Toe board, and I need to validate the move. For some reason it's always outputting the else statement and saying that it's an invalid move.
*note: The numbers displayed on the board are characters, not integers, so I can use the mutator methods to set the board to X or O. If

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
//
//method to make a move
//
void TicTacToe::makeAMove(){
        char move;
        int turns = 1;
        do{
                cout << "Player " << (getCurrentPlayer() + 1) << " make a move." << endl;
                cin >> move;
                for ( int i = 0; i < ROW; i++ ){
                        for ( int j = 0; j < COL; j++ ){
                                if ( board[i][j].getiVal() == move ){
                                        board[i][j].setiVal( players[currentPlayer].getMarker());
                                        DrawBoard();
                                }
                                else{
                                        cout << "Invalid move, please reenter. " << endl;
                                        cin >> move;
                                }
                        }
                }

                DrawBoard();
                switchPlayer();
                turns++;

        } while ( turns <= 9 );

}
int TicTacToe::switchPlayer(){
        if ( currentPlayer == 0)
                currentPlayer = 1;
        else if ( currentPlayer == 1 )
                currentPlayer = 0;

        return (currentPlayer);
}

//sample run
+--+--+--+
|1 |2 |3 |
+--+--+--+
|4 |5 |6 |
+--+--+--+
|7 |8 |9 |
+--+--+--+
Player 1 make a move.
3
Invalid move, please reenter.
4
Invalid move, please reenter.
5
Invalid move, please reenter.

Greetings,
you are going through the rows/collums and checking if the move is the one on that spot, if it isn't you output the message. For instance, when you typed "3", it checked if "3" was on the (1,1) position which is falsen which made it go through the else. When you typed 4, it checked if the "4" was in the position (1,2) since it did another iteration of the inside for and so on.
Thank you so much for your response! Unfortunately, I am really unsure how to fix this. Do you have any suggestions at all? I am really lost with how to fix this validation.
Hello again,
The first solution I can think of is to have a flag (boolean) like validMove, which is set to true if the move is valid. When you get out of the for cicles, you can check if the flag is true or false. If it's true you want to do what your are doing right now after the for's. Else, you want to send the message. Nevertheless, this is a very sketchy solution and it seems to be unneficient, since you'd do the all the iterations everytime you give the program a wrong move.
Would you suggest that the user inputs the individual row and column, would that make the program more efficient?
Could you provide the source for the getiVal() method?
Topic archived. No new replies allowed.