0

For some HomeWork, I need to make a Tic-Tac-Toe game. I make the game with no problems, but now I need to control if a player as win. For that purpose, I need to compare some Char present in an array. So I set up a test with an "if", but it sends me an error (CS0019 in Visual Studio) that says I cannot compare char and expect a bool output. How do I circumvent that?

if ((casesMorpion[0, 0]) != (casesMorpion[1, 0]) != (casesMorpion[2, 0]))
{
  V1 = true;
}

2 Answers 2

1

You cannot have (casesMorpion[0, 0]) != (casesMorpion[1, 0]) != (casesMorpion[2, 0]) on a single line and expect it to work.

You get your error because (casesMorpion[0, 0]) != (casesMorpion[1, 0]) is a bool, and you try to compare it to (casesMorpion[2, 0]) which is a char.

You should split it into two conditions with a logical and &&:

if (casesMorpion[0, 0] != casesMorpion[1, 0] && casesMorpion[1, 0] != (casesMorpion[2, 0]))
{
    V1 = true;
}

Or anything else, since I don't know exactly what you are trying to test.

Sign up to request clarification or add additional context in comments.

1 Comment

This is programmatically fine. And its just that I think both the comparison operations have to be combined with OR and not AND
1

I agree with @Corentin Pane answer. He answered just few seconds before me

Some thing like below could help

var expectedChar = casesMorpion[0, 0]; 
if ((expectedChar != casesMorpion[1, 0]) || (expectedChar != casesMorpion[2, 0]))
{
    V1 = true;
}

!= operation between two operands give a bool. so now it will become bool != char this will give a compilation error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.