-3

I’m trying to make a tic-tac-toe program; I'm adding an if statement to change a variable's value if the condition is met. But when the condition is met, the variable that's value should be changed is 0.

I'm doing this in c++

cout <<player1 << ", which position would you like to add your X?: " << endl;

cin >> x1;

if (x1 == (b)) {
xx1=5; 
}

N.B. When it asks you which position would you like it add your X, I am typing "a".

I expected xx1's value to change to 5 but instead of 5 it was 0.

Edit: I was using the "=" operator instead of the "==" operator. I ran the code and it worked, though now, a couple minutes later, it isn't working. I don't know what I did to make this happen, because the only thing that I did was setting it up for other letters.

1 Answers1

0

To check if variables are equal you should use == operator.

You can read more about comparison operators here

Octoslav
  • 26
  • 1