I need to compare two characters

Sep 9, 2009 at 1:13pm
Hay!

So im trying to create a simple text-based game with c++, i have got verry good results so far, but i dont understand how to do the yes/no thingy

im trying to do this:

char yesorno;
cout<< "blahblahblah, (Y/N)";
cin>> yesorno;
if(yesorno == "n")
{
do
//blahblahblah
}
until(yesorno == "y")


And when i try to compile it sais:

ISO c++ forbids comparison between pointer and integer

can someone tell me how to fix this?
Last edited on Sep 9, 2009 at 1:13pm
Sep 9, 2009 at 1:38pm
Characters are placed in single quotes. if( yesorno == 'n' )
Sep 9, 2009 at 1:50pm
omg thank you THANK YOU!!!!!
Sep 10, 2009 at 5:28pm
Or you could use strings...
Sep 10, 2009 at 6:15pm
I agree with MYST; with a string you can easily check if a string is "yes", "Yes" or "YES" or whatever:
1
2
3
4
5
std::string yes = "yesYesYES";

if (yes.find(yesorno) != std::string::npos) {
    std::cout << "Found " << yesorno << ".\n";
}


which will check if the string yesorno contains any of the above words.
I got the idea from the following python code:
1
2
3
4
if YN in "yY":
    doSomething()
elif YN in "nN":
    doSomethingElse()

where YN was 'y', 'Y', 'n' or 'N'.
Sep 10, 2009 at 6:46pm
closed account (z05DSL3A)
this thread whent over to hear: http://www.cplusplus.com/forum/beginner/14176/
Topic archived. No new replies allowed.