【发布时间】:2012-12-07 03:40:31
【问题描述】:
我需要弄清楚如何验证 2 个条件。
- 检查是否已经播放过之前的号码。
- 检查数字是否在1到9之间。
在任何一种情况下,它都应该循环回到开头。对于第一种情况,它不应该运行,直到用户输入一个尚未播放的数字。
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);
【问题讨论】:
-
那么您的代码有什么问题?
-
您真的应该将您的
while条件重写为while (play > 0 && play < 10)... -
@H2CO3:
while (play > 0 && play < 10)与while(play != 1 && [...] )不相同 -
@Nawaz 忘记了
!操作符,但你没明白我的意思吗? -
@H2CO3:我明白你的意思,但问题是我没有问这个问题。提问者需要理解你的意思,而不是你写的。 :-)
标签: c++ if-statement while-loop do-while