【发布时间】:2017-07-26 20:59:49
【问题描述】:
所以我在测试时遇到问题,以确保 while 循环正常工作。如果为cin
int a;
cout << "What type of game do you wish to play?\n(Enter the number of the menu option for)\n(1):PVP\n(2):PvE\n(3):EVE\n";
cin >> a;
while (!((a == 1) || (a == 2) || (a == 3)))
{
cout << "That is not a valid gametype. Pick from the following menu:\n(1):PVP\n(2):PvE\n(3):EVE\n";
a = 0;
cin >> a;
}
【问题讨论】:
-
哇,这么多括号!您不需要单独的
==测试周围的那些,您可以通过应用德摩根定理摆脱三个测试周围的一对:while (a != 1 && a != 2 && a != 3)更容易阅读......
标签: c++ while-loop