I used:
if ( (nameofgame != "Go") || (nameofgame != "go") )
And we don't use periods "." after exclamation marks "!" typically.
Main Topics
Browse All TopicsI'm newish to c++ and I'm having some confusion about how the 'or'/'||' operator works
more specifically in the if statement I use an or operator so that if nameofgame isn't "Go" or "go" the condition will execute
But it's not working out. It works if I use only one like if (nameofgame != "go") but I've seen examples in books that check two things with 'or'. I've tried just about every combination of the two but it doesn't work (ie. if (nameofgame != "go" || nameofgame!="Go"),etc).
What have I done wrong?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Couple different ways to do it:
if (!(nameofgame == "Go" || nameofgame == "go"))
This would also work, using && operator:
if (nameofgame != "Go" && nameofgame != "go")
Also consider the possibility of making nameofgame all upper or lower case before doing the comparison as that would handle any combination of upper and lower case with only one comparison.
Incidentally, if you want to convert it all to one case then you can do something like:
transform(nameofgame.begin
Then the comparison is just:
if (nameofname != "GO")
If you use that then you will need to add these includes if you don't have them already:
#include <algorithm>
#include <cctype>
Didn't JimU answer this first in http:#25735055 ?
>> but he did not answer the original question or correct the code first.
I think that's exactly what he did. Did you look at his post http:#25735055 ?
Anyway, apparently, neither the author, nor JimU are interested in fixing this, so i'll just disappear in the background :)
Business Accounts
Answer for Membership
by: themrrobertPosted on 2009-11-03 at 15:29:01ID: 25735044
Try this
Select allOpen in new window