2 strings

k i want the functions to go if ans= yes or no but if i type anything it goes to the function.
1
2
3
4
5
6
cout<<"yes or no?"<<"\n";
cin>> ans;
if (ans == "yes"or"no")
{
//functions
}
Last edited on
Read up on the logical operators: http://www.cplusplus.com/doc/tutorial/operators/
i tried
1
2
3
4
5
6
cout<<"yes or no?"<<"\n";
cin>> ans;
if (ans == "yes"||"no")
{
//functions
}]

but it still just does the function if i type anything.
Last edited on
First off, why are you checking both yes and no and still entering the same function? Also, when you use the Logical Operators it should look like this:

if ( ans == "yes" || ans == "no" )
ahhh k ty.I'm just using yes and no as an example.
Bad examples have nothing to do with what you want.

Post the code you are having trouble with and we can help you fix it properly.


Here's an older thread where the poster was interested in getting a verified YES or NO from the user:
http://www.cplusplus.com/forum/beginner/18518/

Good luck!
Topic archived. No new replies allowed.