Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4099022
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:22:46+00:00 2026-05-20T20:22:46+00:00

Greetings, Since my last question about C++, I actually learned quite an amount. I

  • 0

Greetings,

Since my last question about C++, I actually learned quite an amount. I am now comfortable with classes, just not so comfortable with pointers and references yet.

Please note, I am not asking you nesceserally to solve my problem, I’m asking why I’m not getting the wished result.

here are some code snippets that that should help me explain the problem:
Im making a console based tic-tac-toe game(recently started learning C++, this imo is a good way for it)

main.cpp:

//Here I initalise 1 variable and an array
int move;
char board[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' '};

First question: Is there a better way to define empty spaces in a char array?
The reason i’m doing it like this is, I want my tictactoe board to contain an empty space when an X or O has not been set yet.

main.cpp:

if(referee.validateMove(board, move))
{
   board[move] = player2.getToken();
   displayBoard(board);
}

What happens here is easily understood but i’ll explain anyway;

A call to the validateMove method from the object referee is made, and passed 2 paramaters, the move that the player has selected (in between 0-8). and the tictactoe board.

Referee.cpp

bool Referee::validateMove(const char (&board)[9], int& move)
{
    if(board[move] != 'X' || 'O')
    {
        return true;
    } 
    else 
    {
        return false;
    }
}

Here is where the main trouble is, and my last question arises.
As seen before, I passed an array of chars with a size of 9.

The reference to the move variable works well(should i use a reference or pointer?) and it contains the wished result.

At this point, say player 1 just made its move and placed a token in position 2
I now want to place my token as PLAYER 2 on position 2

When I debug with visual studio, I get the following:

0x0024faa8 "  O      ÌÌÌÌÌÌÌÌÌÌÌ"

This is when i hold my mouse on the board parameter.
So the board does know, it is occupied.

Why however does the validateMove method always return true, and is board[move] never equal to O or X?

Thank you for taking the time to read my problem. If you have a question, or I explained something in a stupid matter, you see invalid naming conventions, please notify me. I am a student, and I want to pick up as much as possible.

This problem is resolved. Thanks for those who have answered. Highly appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:22:46+00:00Added an answer on May 20, 2026 at 8:22 pm

    Your condition boils down to this:

    if((board[move] != 'X') || ('O'))
    

    'O' will always evaluate to true in this case, so you always pass the condition. What you want is this:

    if((board[move] != 'X') && (board[move] != 'O'))
    

    To verify, this code runs fine for me:

    #include <iostream>
    
    bool validateMove(const char (&board)[9], int move)
    {
        if((board[move] != 'X') && (board[move] != 'O'))
        {
            std::cout << "True" << std::endl;
            return true;
        } 
        else 
        {
            std::cout << "False" << std::endl;
            return false;
        }
    }
    
    
    int main()
    {
        char board[9] = {' ',' ','O',' ','X',' ',' ',' ',' ',};
    
        validateMove(board, 0);
        validateMove(board, 2);
        validateMove(board, 4);
    }
    

    The output is:

    True
    False
    False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been teaching myself JavaScript over the last Month now, not super consistently
Greetings all, I'm working with a C# solution in VS 2010. Right now, since
Greetings, I am trying to learn pointers in C, I simply want my addtwo
Greetings, I've been with this about 1 or 2 hours and it seems I
Greetings, http://marijn.haverbeke.nl/codemirror/jstest.html works on Safari on PC, but not on an Ipad. Which is
Greetings I may have imagined this but does anyone know if Last.fm previously used
Greetings all, This has confused me ever since I first started coding in C#.
After reading about it for so long, I now have chance to get my
Disclaimer: It's been a while since I last wrote any code. The quality of
Greetings all and please forgive me if my question is too cheap. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.