Im i right to say that you need string.h to compare char objects? If it is, that solves it
Im i right to say that you need string.h to compare char objects? If it is, that solves it
It's a matter of symantics. Technically you don't need string.h (or cstring depending on your compiler) to compare single chars. You do need string.h (or cstring) to compare null terminated char arrays (aka, c_style strings). If you consider a single char to be a char object then you don't need string.h. If you consider c_style string to be char objects you do. I know it's picky, but that's a large part of learning the language. Better to think of single char vs c_style string as opposed to char object. The latter is too vague, string is vague enough!!!!!
Instead of using an else statement to check for illegal statements try this. By the way, this is only a piece of code.
int checker=0;
char yorn;
while(checker=0)
{
cout<<"Choose y or n and input in lowercase";
cin>>yorn;
if(yorn="y")
{
checker=1;
//do some other stuff
}
if (yorn="n")
{
checker=1;
//do some other stuff
}
}