說你的代碼是: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