【发布时间】:2017-12-17 11:24:15
【问题描述】:
这可能是一个非常简单的问题,但是当我输入 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 播放,按 s 停止
谁能帮我解决这个问题?我会很感激的
【问题讨论】:
-
将
if (playstop == s)转换为if (playstop == "s") -
您正在将用户输入与 变量
s进行比较。除非变量s恰好包含字符“s”,否则它不会起作用。 -
显示你的真实代码。
-
什么是
playstop?s是什么?optiongame做什么?请创建Minimal, Complete, and Verifiable Example 向我们展示。当然还有read about how to ask good questions 和learn how to debug your programs。
标签: c++ for-loop if-statement