2017-10-12 19 views
-2

我想让你可以说是或如果你想要一个教程,但它总是运行'cout'的教程如何修复if语句,使它在我可以键入在是或否,它会根据我所说的做,并请告诉我为什么我必须做我必须做的。C++如果语句信读者

#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") 

否则,“是”是不是比较投入,但评估为条件本身,由于C++是运作是真实的(即不假)。
更详细的,任何不是0在某些方面是真实的。对于字符串“是”,存储器地址被采用,并且它不是0.

+0

谢谢,你对我解释得很好,但它不起作用我试过了,并从你的文本中复制了它,但它仍然无效,是的,我改变了它,当他们回答“否”和“否” “这是我的软件,或者我应该尝试一种不同的技术,比如std :: string :: npos!= input.find(”no“||”No“),或者我应该把std :: string :: npos!= input ||找到||之后太谢谢了。 – Gandalf