変数 "check"の完全一致を探したいと思います。ユーザーが「タイプo」または「タイプb」と入力すると、ループは終了します。私はwhile (check != "type o"){...}
を試しましたが、それは動作しますが、2番目の状態では動作しません。私は混乱しています。以下は私のコードです。C++正確な文字列に一致する複数の条件
void sunTypeCheck(string sunCheck){
string check = sunCheck;
transform(check.begin(), check.end(), check.begin(), ::tolower);
while (check != "type o" || check != "type b"){ //This is the problem.
cout << "Please enter a valid type of Sun. Try again: ";
getline(cin, check);
transform(check.begin(), check.end(), check.begin(), ::tolower);
}
}
これは私の主な方法です。
int main(){
cout << "Please enter sun type: ";
getline(cin, typeOfSun);
sunTypeCheck(typeOfSun);
}
ご協力いただきますようお願い申し上げます。私はオンラインを見て、「比較」が、限り、私は第二の条件を含めて、それが動作しません使用してみました、そしてプログラムは常にPlease enter a valid type of Sun. Try again:
'||'(または)のことを考えてください。一方の側が 'true'ならば、式は何に評価されますか? – NathanOliver
'check'が' 'type o '' 'ではない場合に条件を真にしたいと思います。基本的な[ブール代数](https://en.wikipedia.org/wiki/Boolean_algebra)を学んでください。 –