Palindrome- error in in statement

Back to General discussions forum

Victor Soldera     2020-07-24 06:53:32
User avatar

Hey! I'm having a problem in an if statement. It seems to be ignoring all other conditions other than string[j] != ' ';

//Here is the problem! It ignores all other conditions, and if I take them away(other them != ' ', it works
if(string[j] != ' '  || string[j] != ',' || string[j] != '!' || string[j] != '-') {
    aux[count++] = tolower(string[j]);
}

Thanks for your help!

Rodion (admin)     2020-07-24 07:18:53
User avatar

Victor, Hi!

The problem is not in the code, but in the logic which you invented. You say

if character is not space OR is not comma OR...

But it is true for any character. If it is not space then c != ' ' is true, but if it is space, then c != ',' is true. So your condition is always true, that's how OR works.

I leave this to figure out further to yourself, if you don't mind :)

Victor Soldera     2020-07-24 16:19:18
User avatar

Ohh! I see now! Thank you very much for your help! Submitted it now and it worked! Thank you, Rodion!

Please login and solve 5 problems to be able to post at forum