Hi I am trying to get user input for a tic-tac-toe game and am currently in the stage of checking if the inputted value and if it is an invalid number, it keeps repeating the check for input.
Only problem is that it does not recognise the input as only needing to be a number only and will constantly repeat the string over and over again leading to impaired performance of the pc.
int player = 1;
string grid[3][3];// = {'1','2','3','4','5','6','7','8','9'};
int r,c; //r = row, c = collumn, x = grid ref
string x;//grid ref
int grid_number = 1; //number of grid
int input = 0; //user number
//start game
while(1)
{
//draw grid
for (r=0; r<3; r++)
{
for (c=0;c<3; c++)
{
cout<<grid[r][c]<<" ";
}
cout<<endl<<endl;
}
cout<<endl<<"Player "<<player<<", please input a number to play selected square: ";
cin >> input;
r = floor(grid_number/3)-1;
c = ((input-1)%2)-1;
x = grid[r][c];
while(input < 1 || input > 9 || x == "X" || x == "O")
{
cout<<"Grid["<<r<<"]["<<c<<"] is not a valid point, please try again: ";
cin >> input;
system("pause");
}
}
all im trying to do is get it so if the user enters "4"
the computer searches grid[1][1] and check what the value is there.
else "9" will result in a search for the value at grid[2][2].but if the user enters "s" || "0" || "10" || "dwgfcdyuwegduk" it will ask for input again. Any ideas?