+ 2
Why is my code executing one of my "if" statements when I'm entering the conditions of another?
string words; cin >> words; if ((words == "Hi") || (words == "hi")) { cout << "Hello!" << endl; } if ((words == "How are you?") || (words == "how are you?")) { cout << "I'm doing fine, thanks!" << endl;} I'm entering "How are you?" but the program is outputting "Hello!" Can anyone explain to me what's going on?
7 Réponses
+ 1
If you type any string this compiler will treat it as multiple inputs so it is better to assign the value to some variable and then execute it..
+ 1
yes the user wouldn't be able to type "How are you" or Hi but this problem is only with this compiler..I think in turbo c++ we can enter string with space..
0
thank you!
0
But how can I assign the value of a string to another variable?
0
instead of cin>>words;
use words="Hi"
0
But if I use words = "Hai", then the users wouldn't be able to input the word, would they?
0
Thank you so much!