i am trying to compare an element in an array but it gets stuck in a loop. from what i see it doesnt even compare the element. I want to place a x in an array but if there already is an x there i want to place it above it.
#include <iostream>
using namespace std;
const int row = 6;
const int col = 7;
void player (char playgrid [row][col]);
int main()
{
char playgrid[row][col];
for (int currentrow = 0; currentrow <= row; currentrow++)
{
for (int currentcol = 0; currentcol <= col; currentcol++)
playgrid [currentrow][currentcol] = '.';
}
playgrid [6][2] = 'x';
player (playgrid);
for (int currentrow = 0; currentrow <= row; currentrow++)
{
for (int currentcol = 0; currentcol <= col; currentcol++)
cout << playgrid [currentrow][currentcol];
cout << endl;
}
return 0;
}
void player (char playgrid [row][col])
{
int colselect;
int rowselect = 6;
cout << "Enter column select: ";
cin >> colselect;
bool entered = false;
while (entered != true)
{
if (playgrid [rowselect][colselect] != 'x')
{
playgrid [rowselect][colselect] = 'x';
entered = true;
}
rowselect -= 1
;
}
}