September 1st, 2012, 04:31 PM
It != that is "not working" - that is hardly plausible! Rather it is your boolean logic lat his flawed. See here
Boolean logic and algebra are the fundamental mathematics of computing. You need at least an intuitive of not a rigorous mathematical understanding of it.
Originally Posted by salem
while ( !( choice == 1 || choice == 2) )
Which is equivalent also to:
while( choice != 1 && choice != 2 )
You can take your pick, I suggest the latter since it only requires a single change of operator to correct your code. Intuitively you might describe the first as:
"while neither 1 nor 2
and the second as:
"while not 1 and not 2
you can see that in English they mean the same thing, whereas your (arbitraryproc's, not salem's) code reads
"while not 1 or not 2
which is true for any value, because when its 1 its not 2, and when 2 its not 1, and when it is anything else its neither 1 nor 2!
Consider the following:
NOT(A) AND NOT(B) == NOT(A OR B)
NOT(A) OR BOT(B) == NOT(A AND B)
these are known as De Morgan's Laws
Last edited by clifford : September 1st, 2012 at 04:37 PM.