hi every 1 i was hoping some 1 might be able to help me out i've run out of ideas. I have to create a o and x game for my C++ assignment im going to fail this course if i cant get it to work which is annoying becuase im doing well in the other modules.The code is below ive commented it best i can. THE PROBLEM- 2d array will display and a grid reference input the x or o is then displayed but then when the next turn swings around and a grid reference is entered the first move is lost and no longer displays!!!
Any help would be great thank in advance neil
The problem code -
char bgrid[3][3];//2d array which will be used as a grid for the beginners game
int width,height;//variables used to create the grid
int gridref1,gridref2; //variables used for placing data into a spersific postion of the grid
int turn=0;
//start of loop to place player data destination into the grid if player inputs
//an incorrect grid reference the loop will loop back and ask the player again
do
{
cout<<"Please choose a row. \n";
cin>>gridref1;//user input the row they wish to use
cout<<"Please choose a column. \n";
cin>>gridref2;//input the culom they wish to use
cout<<endl;
}
while(gridref1>3 || gridref2>3 ||bgrid[gridref1-1][gridref2-1]=='O'||bgrid[gridref1 -1][gridref2 -1]=='X');
//end of loop to place player data into the grid
//start of if statment to create the turn based system of the game
turn++;
if(turn%2==0)
{
bgrid[gridref1-1][gridref2-1]='O';//change this later so user can choose what to be
}
else
{
bgrid[gridref1-1][gridref2-1]='X'; //change this later so user can choose what to be
}
//end of if statement to create the turn based system of the game
for(width=0; width<3; width++)
{
for(height=0; height<3; height++)
{
cout<<bgrid[width][height];
}
cout<<endl;
}
}
while(turn<9);