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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:10:28+00:00 2026-06-16T05:10:28+00:00

I’m a newbie in C++ programming and I’m following this book called jumping into

  • 0

I’m a newbie in C++ programming and I’m following this book called jumping into C++ by Alex Allain, there’s a tic-tac-toe exercise in the book and I’m having a hard time completing that exercise, so far what I’ve done is to prompt user to enter X or O value, which get stored in a 2d array, I want to track if for example char X appeared 3 times in the array, so far I use counter++ but it only increment once. below is the source of what I’ve done so far hopefully it will make my question much more clearer and let me know as well how I’m doing in terms of the way my codes look such as its structure and functions:

#include "stdafx.h"
#include "iostream"
#include "string"

using namespace std;

void display_array(char array[][3]);
void check_input(char array[][3], int input);
void check_winner(char array[][3]);
int check_x(char array[][3]);
int check_o(char array[][3]);

int _tmain(int argc, _TCHAR* argv[])
{
    char array[3][3];
    int counter = 0;

    for(int row = 0; row < 3; row++){

        cout << "\n";

        for(int col = 0; col < 3; col++){
            counter++;
            array[row][col] = counter;
        }
    }

    display_array(array);

    system("PAUSE");
    return 0;
}

void display_array(char array[][3]){

    int position_input;
    string symbol_input;

    do{

    for(int i=0; i < 3; i++){

        for(int j=0; j < 3; j++){
            cout << " [ ";
            cout << array[i][j];
            cout << " ] ";
        }
        cout << "\n";
    }

    cout << "Position: ";
    cin >> position_input;

    check_input(array, position_input);


    }while(position_input != 0);
} 

void check_input(char array[][3], int input)
{
    char user_input = input;

    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            if(user_input == array[i][j])
            {
                cout << "array[" << i << "][" << j << "] replace with: ";
                cin >> array[i][j];

            }   

        }
    }
    check_winner(array);
}
void check_winner(char array[][3]){
    cout << check_x(array);

    if(check_x(array) == 3){
        cout << check_x(array);
    }

    else if(check_o(array) == true){
        cout << "o";
    }

}
int check_x(char array[][3]){
    int counter, x[3];
    counter = 0;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(array[i][j] == array[i][j]){
                counter++;
            }
            x[i] = counter;
            return x[i];
        }
    }

}
int  check_o(char array[][3]){

    int counter;
    counter = 0;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(array[i][j] == 'o'){
                counter++;
                return counter;
            }else{
                return counter;
            }
        }
    }
}
  • 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-06-16T05:10:29+00:00Added an answer on June 16, 2026 at 5:10 am

    You have a bunch of little problems but the most immediate one seems to be this kind of thing:

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(array[i][j] == 'o'){
                counter++;
                return counter;
            }else{
                return counter;
            }
        }
    }
    

    Regardless of whether the element tested is an ‘o’ or not you are going to return after one loop. Change it to something like this:

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(array[i][j] == 'o')
                counter++;
        }
    }
    
    return counter;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.