I'm making a C++ game for an assignment. This is what I have so far (its far from complete since its a group project). I'm missing some functions in here because its a group project, and my friend is making that function.
The problem I've hit is that whenever I input the coordinate, the program would enter the X and O coordinate increment by 1. For example, if I enter 4, it would place the O at 5. I tried using an "x--" to get past that, but it doesn't seem to work.
Another problem is my X are not appearing. I have no idea why really...
Sorry if I can't describe properly. I'm not a native English speaker.
Edit: I fixed the above problems in this updated code. However, I'm having problems in that when player 2 inputs in a space already occupied by player 1, it will overide it.
You're decreasing it after using the value. In other words, you're taking the initial value and using it as an array index, and then decrementing it afterwards.
I fixed the above problems in this updated code. However, I'm having problems in that when player 2 inputs in a space already occupied by player 1, it will overide it.
I believe the problem is here, but isn't sure how to fix it
The problem may be in the following if statement, which looks weird to me:
if (board[x] != 'O'||'X' ==true)
What this means is that the following two conditions are checked, and that if either of them is true, then the entire condition is true:
board[x] != 'O'
and
'X' ==true
Since 'X' has a non-zero value, that second condition will always be true, which means that the entire OR condition will always be true.
It looks to me that what you're trying to do is check that the board position doesn't have either an 'X' or an 'O'. If this is the case, the logic should be that both
board[x] != 'O'
and
board[x] != 'X'
must be true.
A simpler approach would be to ensure that the elements of board are initialised to some value that indicates it hasn't been filled yet, and then just check whether the element still has that initial value.