There's a logic error in your code.
Try this:
if(answer == 'Y' || answer == 'y')
{
return true;
}
if(answer == 'N' || answer == 'n')
{
return false;
}
You should also possibly output a message in case the user decides to type something other than 'Y'
,'y'
,'N'
or 'n'
.
Also, I'm not 100% sure about this, but I think that your code is always returning true
in the first if statement because you are checking to see if 'y'
is true, which I think it always is.
if(answer == 'Y' || 'y')
{
return true;
}
Any value other than 0 would equate to true, and the character 'y'
when treated as an integer is equal to it's corresponding ASCII code (121 in this case).