I need to compare two characters

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
Characters are placed in single quotes. if( yesorno == 'n' )
omg thank you THANK YOU!!!!!
Or you could use strings...
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'.
closed account (z05DSL3A)
this thread whent over to hear: http://www.cplusplus.com/forum/beginner/14176/
Topic archived. No new replies allowed.