【发布时间】:2017-06-10 15:12:44
【问题描述】:
所以我目前正在尝试为我的 C++ 类制作一个基于文本的游戏,但似乎无法弄清楚如何让 if-else 语句仅在有以前收集的项目以用于故事的情况下执行有意义。如果物品不在库存中,玩家的选项将再次循环,让他们选择不同的选择。我尝试这样做:else if(input6 == "rub" || inventory[0] == "Purple Fruit") 但它只会执行该语句,而不管玩家是否拥有该项目。谢谢你的时间!!我是认真的。
do {
cout <<"You gotta start doing something quick before the swelling gets worse" <<endl;
cout <<"Options are: \"rub\" the random substances oozing from your purple fruit onto your swelling neck, \"keep\" following the tracks until you could get help from the humans if those tracks actually belong to a human, or \"look\" around for anything to help cure your swelling neck\""<<endl;
cin >>input6;
if (input6 == "keep")
{
cout << "" <<endl;
return 0;
}
else if (input6 == "look")
{
cout <<"Good luck" <<endl;
}
else if (input6 == "rub" || inventory[0] == "Purple Fruit")
{
cout << ".." <<endl;
return 0;
}
} while (input6 != "grab");
cout <<"Out"<<endl;
inventory[1] = "Pink Sap";
cout<< inventory[1] <<endl;
【问题讨论】:
-
如何比较字符串?
标签: c++ if-statement