2017-10-12 24 views
-2

チュートリアルが必要な場合はYesまたはYesと答えることができますが、チュートリアルでは常に「cout」が実行されます。if文を入力して入力できる場所を修正する方法はい、いいえ、それは私の言うことに応じて行い、どうして私はそれをやらなければならないのか教えてください。C++ Ifステートメント・レター・リーダー

#include <iostream> 
#include <istream> 
#include <string> 
using namespace std; 

int main(){ 
string name; 
cin >> name; 
cout << name << " Will Now Be Your Business Name"; 
cout << " Would You Like A Tutorial? "; 
string input; 
cin >> input; 
if (input != "Yes" || "yes"){ 
    cout << "You First Start With Naming Your Business Which Is What You Did And Then You \nCreate A Product By Entering In 'Create_Project' This Is How You Make Money "; 
} 
else if (input != "No" || "no"){ 
    int money = 1000; 
    cout << "Money: " << money; 
    } 
} 
+1

'if(input!=" Yes "||" yes ")'は**常に** trueです。 'if(input!=" Yes "|| input!=" yes ")'を意味しましたか? 'else if(input!=" No "||" no ")'の場合も同様です。 –

答えて

0
if (input != "Yes" || "yes") 

は、あなたがそうでなければ

if (input != "Yes" || input != "yes") 

たい、 "yes" と入力と比較するが、条件自体として評価し、原因C++があるの働きに(すなわち真ではありません。ありません偽)。
さらに詳しく、何らかの形で0でないものはすべて真です。文字列 "yes"の場合、メモリアドレスが取られ、0ではありません。

+0

ありがとう、あなたはそれを私によく説明しましたが、うまくいきませんでした。それを試してテキストからコピーしましたが、それでもうまくいかず、はい、私は「いいえ」と「いいえ」 "それは私のソフトウェアですか、私はstd :: string :: npos!= input.find(" no "||" No ")のような別のテクニックを試すべきですか? .findの後に||あまりにも感謝。 – Gandalf

関連する問題