I am new to c++ and i just started working on a tic tac toe game.I put the playerturn variable before my primary loop but it still only inputs the 'X' character. Basically, i do not know how to get the playerturns to change. Obviously this is not a complete program, but it is the part that gets messed up.
You could implement the bool playerturn variable instead of an integer
and switch directly in your first if statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
bool playerturn = false;
char playermarker;
if (playerturn == false)
{
playermarker = 'X';
playerturn = true; // Next turn It Will Be The ( O )
}
else
{
playermarker = 'O';
playerturn = false; // Next turn It Will Be The ( X )
}
Thank you that worked. I did have to move the playerturn outside of the main loop but it did work in the end. Since i am still new to this, can you explain how your code works exactly. I dont want to just copy and paste, i actually want to understand the idea.
First of all ,before your main do/while loop , you have a declared variable of bool type
A bool variable can only contain two possible values , in this casefalse or true or it can also be 0 or 1 like machine language (binary) .
In this case changing your integer for a bool type variable optimized the space that you're using in memory to use your program, that's just an example because in a little program it won't even be noticeable but in bigger project it might.