I need to figure out how to validate 2 conditions.
- Check if a previous number has been played.
- Check if the number is between 1 and 9.
In either case, it should loop back to the beginning. With the first situation, it shouldn’t run till the user enters a number that hasnt been played.
do
{
cout << "Interesting move, What is your next choice?: ";
cin >> play;
Pused[1] = play;
if(play != Pused[0] && play != cantuse[0] && play != cantuse[1] )
{
switch(play)
{
default:
cout << "Your choice is incorrect\n\n";
break;
}
}
}while(play != 1 && play != 2 && play != 3 && play != 4
&& play != 5 && play != 6 && play != 7 && play != 8 && play != 9);
Dis_board(board);
Instead of do-while loops, i like to use the combination of infinite loops +
breakstatements, like this:In the code above, the two comments represent code, which may itself contain loops. In order to reduce confusion, you might want to stuff this code into a separate function. For example, to input the choice:
Note: to implement good handling of user errors, you also have to account for the case when the user enters nonsense instead of a number; look up
istream::ignoreandios::clearfor that.