0

I need some help regarding logical 'or' operator, if-else conditions and strings.

First read my following program :- #include <iostream> using namespace std; int main () { string a,b = "Hi user"; cin>>a; if (a == "Hello"){ cout<<b; } else if(a == "Hey"){ cout<<b; } return 0; } It's just an example of some code I've been doing and it worked well ,but I just want to make it more compact and reliable in case of more conditional strings,so I did the following :- if(a == "Hey" || "Hello"){ cout<<b; } But unfortunately, it didn't worked. Please help me out in this.

2nd Apr 2017, 9:53 AM
Himanshu Kumar
Himanshu Kumar - avatar
4 Respuestas
+ 22
if (a == "Hey"||a == "Hello") { cout<<b; }
2nd Apr 2017, 9:57 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
unfortunately Your method is not supported - some days i had the sam problem. other tip is to use a regullar expressions (if exiats like in java) i'm condused why a==(x||y) not works...
2nd Apr 2017, 10:36 AM
Michał Bujakowski
Michał Bujakowski - avatar
+ 1
Thank you ValentinHacker. It worked smoothly :)
2nd Apr 2017, 1:01 PM
Himanshu Kumar
Himanshu Kumar - avatar
0
have you tried dipping it in rice?
5th Oct 2020, 3:56 AM
Samir Orozco
Samir Orozco - avatar