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 6199397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:10:51+00:00 2026-05-24T04:10:51+00:00

Here is my new edited code I am having trouble with my final if

  • 0

Here is my new edited code I am having trouble with my final if loop for the X and O’s stored inside an array. I am trying to check if there is an X or O already inside the array or not. If there is one it asks the user for another input then start over again however when i run the program this happens:

1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number: 1
player X your number is 1
X | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number: 1
Please enter another Number2
player O your number is 1
O | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number:





char c;


        cout << "Please Enter Box Number: ";
        cin >> c;


        if (c > '9' || c < '0')
        {
            // error message
            cout << "please enter a number 1-9" << " ";
            cin >> c;
            cin.ignore(numeric_limits<int>::max(), '\n');

        }

        if (c < '9' || c > '0') 
        {
            int number = c - '0';

            if (board[number - 1] == 'X' || board[number - 1] == 'O') 
            {
                cout << "Please enter another Number";
                cin >> c;
                cin.ignore(numeric_limits<int>::max(), '\n');

            }
            else if (board[number -1] != 'X' || board[number - 1] != 'O' ) {
                if (player == 'X')
                { 
                    player = 'O';
                }
                else 
                {
                    player = 'X';
                }




                cout << "player " << player <<  " your number is " << number << endl;
                // Your implementation here...



                board[number - 1] = player;

            }


        }







    }
  • 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-24T04:10:52+00:00Added an answer on May 24, 2026 at 4:10 am

    First the second question (the easy one):

    Return exits from the current function. So, after the return, no further instruction in your function is executed. You should remove the return and put the rest of the code (that should not be executed if the input is not valid) in the else block of that if.

    First question:

    • Why do you check that the index of each position in the array (as in board[7] = ‘8’). You already know the position, what you need to mark in each cell is the player who uses it; for example set values of ‘X’ (player 1), ‘O’ (player 2), ‘ ‘ (empty).

    • Instead of nine “if”, it will be easier if you convert your input ‘c’ into an integer and use it as an index. With ASCII characters (I do not know if this still workds with WCHAR, UTF-8 and so on) you could make it quick and dirt:

      int k = c - '0';

      board[k] = player;


    Edit:
    Taking into account checking that the square is not already used:

    int k = c - '0';
    if (board[k] == ' ') {
      board[k] = player;
    } else {
      cout << "This square is already used";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am new here. i have a slight problem; PLease look at the following code
An edited version of the java code: FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
I'm having some trouble with this problem in Project Euler. Here's what the question
I am trying to loop through an array of products. I was wondering if
I am new here so first of all my greetings to you I am
I'm new here to stackoverflow, so bear with me. I have a book that
I'm new here and I hope anyonte can help me. I have WCF Service
I am new here. I would like to know how can I display HTML
Based on my previous question here my new concern is how do I unit
I'm new around here and i have a little problems with a C# application.

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.