If statement between numbers

Hi, I am trying to make some input code so that if the user enters any number between 1 and 9 then it is valid, if not between 1 and 9 and is any other number OR letter then it will be invalid.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
	}

}
Last edited on
how about

if ((choice4 > 0) && (choice4 <=9))
Topic archived. No new replies allowed.