here is my code. I want my if statement to work if the user types in Yes or yes. When I take out || and the "yes" My program works fine and when the user types in "Yes" it works. I wanted to make my program better and also have it so that when they type in "yes" to work. Can someone help me figure this out? Thanks!
{
cout<<"Would you like to begin?\n";
cin>>answer;
if (answer=="Yes" || "yes") {
continue_1=true;
google=false;
}
else {
if (answer=="No" || "no" ) {
cout <<endl<< "have a nice day\n";
google= false;
return 0;
}
You are doing the or on the strings, not on the query - you want:
To be more generic about it though you could convert the string to lowercase and then compare that with "no", which will handle "No", "NO" and "no" for you.
Quite a common alternative approach is to just check that the first character in the string is either N or n. That also picks up things like Nope, etc.