-3 c++ loops infinite while-loop
这不接受任何答案:
cout << "Restart yes or no: ";
cin >> retry;
while (retry != "yes" or retry != "no"){
cout << "Restart yes or no: ";
cin >> retry;
system("cls");
}
Run Code Online (Sandbox Code Playgroud)
如果任何人可以提供替代/修复,将不胜感激.
每个字符串都不同于"yes"或"no".你的意思是环路,只要该字符串从不同的是这两个 "yes"和"no"-这意味着使用逻辑"与"操作,而不是"或"运算符:
while (retry != "yes" && retry != "no") {
Run Code Online (Sandbox Code Playgroud)