Because comparison doesn't work that way. 'Y' || 'y'
is a logical-or operator; it returns 1
(true) if either of its arguments is true. Since 'Y'
and 'y'
are both true, you're comparing *answer
with 1.
What you want is if(*answer == 'Y' || *answer == 'y')
or perhaps:
switch (*answer) {
case 'Y':
case 'y':
/* Code for Y */
break;
default:
/* Code for anything else */
}