for all you c++ gurus.

acidrain - its cos 111U through unisa....

thanks a lot guys -
will see if I can wrap my head around it
 
Code:
Truth Tables

AND

P  Q  |  P AND Q
-----------------
T  T        T
T  F        F 
F  T        F
F  F        F

OR

P  Q  |  P OR Q
-----------------
T  T        T
T  F        T 
F  T        T
F  F        F
 
AND is the same as && in C++
OR is the same as || in C++

Always draw truth tables if you are getting confused. OR in computer science is not used in the exclusive sense as it sometimes is in English
 
AND is the same as && in C++
OR is the same as || in C++

Always draw truth tables if you are getting confused. OR in computer science is not used in the exclusive sense as it sometimes is in English

To be accurate & and | is like AND, OR.

&& and || are short circuit evaluations but in essence provides the same functionality as AND, OR
 
i'm in jhb so probably not :P
unless you coming up
 
To be accurate & and | is like AND, OR.

&& and || are short circuit evaluations but in essence provides the same functionality as AND, OR

Sorry, but '&&' represents "LOGICAL AND", whilst '||' represents "LOGICAL OR".

'&' and '|' are binary operators.

Deenem was correct in clarifying BT6LW's problem:

- Saying "while (num1 != 0 && num2 != 0)" implies the loop condition is true when both values are simultaneously not zero. So if one of the 2 is zero, the condition evaluates to false, causing the loop to exit.

- If you want the loop to stop only when both variables are zero, it's correct to use "while (num1 != 0 || num2 != 0)". This evaluates to true if either variable is not zero. So if both are zero, the condition is false, causing the loop to exit.
 
I want it to exit the loop if num1 = 0 and num2 = 0....

I haven't coded in C++ for more than 4 years (SAS and visual Basic etc), but the solution you're looking for is as simple as changing the != to ==.

Num1=0, Num2=1 ==> false
Num1=1, Num2=0 ==> false
Num1=1, Num2=1 ==> false
Num1=0, Num2=0 ==> true

If this is what you want, just use the && and whatever "is equal to" is in C++ (hence my suggestion of ==)
 
Top
Sign up to the MyBroadband newsletter
X