Hi, I am wanting to have it so that if a player does not enter a number between 1-9 then it should output "incorrect input", I am unsure on the way of going about this and am hoping for insight by someone who does.
1 2 3 4 5 6 7 8 9 10 11
//integer for input
int choice4;
//players turn
cout << endl;
cout << "It's " << player << "'s turn. " << "Type the number of the field: ";
cin >> choice4;
choice4--;
grid[choice4 / 3][choice4 % 3] = player;
//incorrect input statement
Ok this is what I have, although there's a problem, with if a letter is inputted then the program repeats the Input() function infinitely, any way around this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//integer for input
int choice4;
//players turn
cout << endl;
cout << "It's " << player << "'s turn. " << "Type the number of the field: ";
cin >> choice4;
if (choice4 < 1 || choice4 > 9)
{
cout << "Invalid Input." << endl;
Input();
}
else
{
choice4--;
grid[choice4 / 3][choice4 % 3] = player;
}
void Input()
{
//integer for input
int choice4;
//players turn
cout << endl;
cout << "It's " << player << "'s turn. " << "Type the number of the field: ";
cin >> choice4;
if (choice4/*Not between 1 and 9*/)
{
cout << "Invalid Input." << endl;
Input();
}
else
{
//edits grid, if 2 replaces 2 field with X or O
choice4--;
grid[choice4 / 3][choice4 % 3] = player;
}
}
This is the input function where a player must enter between 1 and 9 and if not then it states that it is not valid input, I don't see how I can adjust my code in the way you have displayed
I literally gave a generic simple function to do what you want to do, and then gave you an example of how to use it. All you have to do is copy getChoice essentially.