Question: Logic Operators.

Hello Everyone,

I have a question regarding logic operators used on Char data type:

Q: Write the logical expression for: "ch is any character but not an alphabet".

The first thing comes to my mind is: (ch = ch && ch != a); Assuming that "ch" and "a" are identifiers that holds an alphabet.....I have no idea if this made any sense.

Also, how do I interpret "but" in the above question? should I use the "AND" or the "OR" logic operator on this?

Thank you all for your help :)
Last edited on
Assuming ch is for character and a stands for the set/array of characters in the alphabet,
(ch != a[counter])
Also be careful of confusing yourself over the equality operator == and the assignment operator =
ch is always a character so you don't need to test that.

I don't understand how a character can be an "alphabet", maybe because English is not my first language, but I guess they mean it should not be a letter in the English alphabet. You can use the isalpha function to do that.

http://en.cppreference.com/w/cpp/string/byte/isalpha
Last edited on
Alright, thanks everyone. Just handed in my assignment and hopefully it's correct. And thanks for reminding me of the equality operator.....I always forget to add that extra equal sign lol.
Topic archived. No new replies allowed.