i have an array that looks like this after it has been populated:
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .

When i enter the input of 1 it should put a 'O' in the array at [6][0] but while doing that it also enters a 'O' at [5][7] and it looks like this:

. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . 0
0 . . . . . . .

how can i make it so it only enters where it should go.

playerSymbol is 'O' , player is 1, col 7

int playerMove (char array [][COL], char playerSymbol, int player)
{
 int colselect = 0;
 int rowselect = 6;
 cout << "Player " << player << " move: ";
 cin >> colselect;
 
 bool entered = false;
 
 while ((entered != true) && (rowselect >= 0))
 {
  if (array [rowselect][(colselect - 1)] == '.')
   {
   
   array [rowselect][(colselect - 1)] = (playerSymbol);
   entered = true;
   }
  else 
   rowselect -= 1;
  
 }
 
 if (rowselect < 1)
  {
  cout << "invalid input" << endl;
  playerMove(array, playerSymbol, player);
  }
  
  
 return colselect;
}

Out of curiosity, could your printing code have an off-by-one error to print the same data for the last char in one row and the first in another?

no i tried it without the -1 but i didnt make a difference, the reason for the minus 1 is that in the main function i ask for which column to enter the 'O' in and then i minus 1 from that becasue of the 0 base

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.