I have a tic tac toe game for class and I thought I had it all done but it will not switch from 1 player to the other where am I going wrong. Any help would be appreciated.
Still not figureing what I done wrong? This is why I am having a problem with this I am so confused. I got this far but getting the rest I am so confused.
guestgulkan was trying to point out a few problems.
For the first one, you have the line: currentPlayer = ' ';
In that line, you're clearing currentPlayer. It doesn't make sense that your very next line is an if statement about currentPlayer because you already know exactly what currentPlayer is: currentPlayer = ' '.
That's kinda like deleting everything in a document and then wondering what's in the document. It doesn't make sense. Because you just cleared it, you know that there's nothing in it. Same deal with currentPlayer. Since you just set it ' ', you know that it's ' '.
The other big problem is that you're using if (currentPlayer ='X').
You probably meant if (currentPlayer == 'X').
If you've used something like Basic or Visual Basic before, you're probably used to using the equals sign for both assignments and comparisons. In C++, though, it's different. = is for assignments only. == is for comparisons.
In C++, if (currentPlayer ='X') means:
1. Set currentPlayer equal to 'X'.
2. Do whatever is in the if statement if the previous check was true. Otherwise, do whatever's in the else statement. (But because assignments to anything other than NULL are considered to be TRUE, setting something to 'X' will always be TRUE. So you're always going to go the TRUE path, never the FALSE one.)
What you want is: if (currentPlayer == 'X')
This means:
1. Check to see if currentPlayer is 'X' or not. Return true if so, false if not.
2. Do whatever is in the if statement if the previous check was true. Otherwise, do whatever's in the else statement.
Ahhhh Thanks chemical that was a little more explanatory. I am new and struggling emmensily with this I was lucky I got this far. After guestgulkan I stared and moved things around trying to figure out exactly what was going on and finally posted again because I was so frustrated and confused. I actually didn't know that when I had currentPlayer = ' '; that this was like clearing everything, I thought it was to let me declare it later like int = 0.
I have it working now Thanks for the time and very detailed answer. I actually understand more of the statements and signs now and should help me on my next project now that I can grasp more of it.