lundi 23 février 2015

C++ How to restart an if statement?

Say your code is:



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 whoever is using the code types something else besides "Door" or "Candle" (Or any variant), what would the code be to restart the if statement so it re-asks the first question?


Ex: User inputs: "dance"


Output: "I don't understand "dance". What do you do?"


or something similar.


Aucun commentaire:

Enregistrer un commentaire