说你的代码是:C++如何重新启动if语句?
cout << "You wake up in a room. There is a small lit candle and a door. What do you do?" << endl;
string startout;
getline(cin, startout);
if (startout == "Door" || startout == "DOOR" || startout == "door" || startout == "Open Door" || startout == "open door" || startout == "OPEN DOOR" || startout == "Open door" || startout == "Open the door" || startout == "open the door") {
cout << " " << endl;
cout << "You move to the door but its too dark to see anything besides the outline of it." << endl;
} else if (startout == "Candle" || startout == "CANDLE" || startout == "candle" || startout == "Pick Up Candle" || startout == "PICK UP CANDLE" || startout == "pick up candle" || startout == "Pick up candle") {
cout << "You pick up the candle then move to the door. With the light from the candle you can see the door well. What do you do?" << endl;
};
如果使用的代码类型的东西,除了“门”或“蜡烛”(或任何变体),还可以将代码是什么重启if语句,因此重新谁是 - 问第一个问题?
例如:用户输入:“跳舞”
输出:“我不明白,‘跳舞’。 你是做什么?”
或类似的东西。
所以...你想要一个“循环” – 2015-02-23 18:18:20
我是在Reddit上帮助你的人 - 一旦你开始将它应用到你的树的每一个分支上,它就会变得非常难看。你真的需要开始研究使用有限状态机而不是真正深层的if语句树。 – 2015-02-23 18:32:23
你也应该把你的输入变成小写,然后你只需要比较'startout ==“门”||“。 startout ==“开门”,而不是每个大写字母的组合。 – 2015-02-23 18:33:13