循环的C 不会终止
c++ for loop does not terminate
这可能是一个简单的问题,但是当我输入s以停止时,我的以下代码不会终止。
for ( roundNr = 1;roundNr <=3; roundNr++) {
optiongame(roundNr);
std::cout<<"Do you want to continue with the game? Press s for stop or press p for play n";
std::cin>> playstop;
if (playstop == s) {
break;
}
}
其中:optiongame是某些功能,具有不同的roundnr,但是这很好。PlayStop是用户的输入,即他是要继续选项游戏还是想停止。为此,他可以按P进行p播放,而S停止
有人可以帮我吗?我会感谢
问题在if (playstop == s) {
中,我认为您的代码中有任何名称s的变量,因为这没有任何错误,因为您试图将变量与变量进行比较,但是您需要更改将变量值与" S"进行比较:尝试以下操作:
s = 's';
for ( roundNr = 1;roundNr <=3; roundNr++) {
optiongame(roundNr);
std::cout<<"Do you want to continue with the game? Press s for stop or press p for play n";
std::cin>> playstop;
if (playstop == s) {
break;
}
}
相关文章:
- while 循环不以哨兵值终止
- 在这个无限循环中,当输入 0 时终止,当输入 int 范围之外的任何内容时,程序行为不正常
- C++ 即使不满足条件,循环也会终止
- 为什么 EOF 在循环扫描期间没有终止?
- 对于检查 >=0 终止条件时的循环索引类型
- 程序在终止循环后不接收输入
- 即使我尝试递减 t,While 循环也没有终止
- 如何修复不会在退出选择时终止的 do-while 循环
- 如何用字符终止整数输入循环?
- 读入变量时循环终止,'Range_error' on C++
- 当我输入非整数值时,我的二次方程代码终止,如何让它正确循环?
- 如何正确终止此循环?
- 多个查询的循环过早终止
- 程序终止,状态为 -1073741510 在 for 循环的中间,将输入分配给二维数组
- 终止具有特定字符的循环
- 程序终止,而不是继续整数输入验证循环
- 程序似乎在 for 循环 - C++后静默终止
- 循环终止不正确时
- C :终止循环的最优雅方法,该循环在字符串向量上迭代
- 如果未检测到alpha,则终止循环