所以,我试着写一个文本冒险的东西,每当我尝试将一个字符串与一个消息进行比较时,无论我写什么,我都会得到相同的输出...我已搜索并搜索,但不能找到答案......我有使用Java,LUA和一些HTML编程的经验...也许我试图做的事情与Java的方式太相似了?好吧,这里有一些代码可能最终有所帮助。
string sex;
cout << "Would you like to be a boy or a girl?" << endl;
cin >> sex;
cout << sex;
//statement to declare what you are...
if (sex == "boy" || "Boy"){
cout << "You have chosen to be a boy!" << endl;
}
else if (sex == "girl" || "Girl"){
cout << "You have chosen to be a girl!" << endl;
}
else{
create();
}
任何形式的帮助将不胜感激。谢谢。
答案 0 :(得分:1)
变化
if (sex == "boy" || sex == "Boy"){
cout << "You have chosen to be a boy!" << endl;
}
else if (sex == "girl" || sex == "Girl"){
cout << "You have chosen to be a girl!" << endl;
}
到
if (sex == "boy" || sex == "Boy"){
cout << "You have chosen to be a boy!" << endl;
}
else if (sex == "girl" || sex =="Girl"){
cout << "You have chosen to be a girl!" << endl;
}
原因是if (sex == "boy" || "Boy")
语句,第二部分总是评估为真。