2017-10-12 76 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