Not able to apply

Hi guys, I posted a thing earlier about help on a tic tac toe program. I am posting this because its as if I am not able to apply any of the information Ive learned and I dont know what to do. I go through the tutorials on this site until they make sense and I grasp the concept. But I cant apply any of them to save my life. I have no idea how to make this tic tac toe program, Ive been looking online for hours, everything Ive come across makes absolutely no sense. Should I buy a tutorial book or something?
How far have you gotten?

A good idea may be to think logically about how a tic tac toe game works. Think, you first draw a grid... okay make a function for that.
Then X chooses where to go, make a function for that.
Then you check if someone has won, make a function for that.
Then O chooses where to go, make a function for that.
Then you check if someone has won, make a function for that.
Repeat in a loop until someone has won.

Start your program off there and then start filling in the functions.
well I just got to the classes section but I dont understand them at all. So I have the board printed in a function and I also have two global arrays (1-9). One of the arrays is with pointers.

#include <iostream>
using namespace std;
char slot[3][3]={'1','2','3','4','5','6','7','8','9'};
char *pointer[9]={&slot[0][0], &slot[0][1], &slot[0][2], &slot[1][0], &slot[1][1], &slot[1][2], &slot[2][0], &slot[2][1], &slot[2][2]};
char player_turn='1';

void print_board()
{
cout<<*pointer[0]<<" "<<*pointer[1]<<" "<<*pointer[2]<<endl;
cout<<*pointer[3]<<" "<<*pointer[4]<<" "<<*pointer[5]<<endl;
cout<<*pointer[6]<<" "<<*pointer[7]<<" "<<*pointer[8]<<endl;
}
int main()
{

print_board();
cout<<"player"<<player_turn<<"'s turn.";
cin>>*pointer;
print_board();

system("pause");
}
Ok, looking at what you have and where you can go from there:

A loop, where the player inputs the number representing the slot. If they enter an available slot, you assign that character to the slot through the pointer:

*pointer[player_input] = character;

You'll need to validate that the input slot is:

1. Within the bounds of 1-9. Array indexing starts at zero, so any number input would need 1 subtracted from it before bounds checking.
2. Not already taken. Simply look at the pointer to see if it contains an X or O. If it does, tell the player to try again.

There will be nine successful inputs before the board is filled up and you check for a winner. Since there must be three successive Xs or Os in any row, col or along one of the two diagonals, you can simply compare using an if statement to see if the contents of those slots are equal to each other. Like if( a == b && b == c), then you know a == c also.
Last edited on
Alright I understood most of that but how am I going to assign player_input to every number of the array
can I use *pointer as the player input? It seems kind of odd
Topic archived. No new replies allowed.