Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

visual c++ newbie needs help with "and"

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
0
0
US
Hi all,

I am needing to make a do-while loop in a command-line program. my problem is that I cannot seem to find in my book, or the e-book version (slightly different) how to write "and" and "or" statements. I tried using && (like javascript) and ||, but they dont seem to work

here is the code snippet:

while ((iuserChoice< 1) || (iuserChoice <2));

I need it to say: while iuserChoice is less than 1 or greater than 2.


I am using Microsoft Visual C++


Thanks for any help! Robert Carpenter
questions? comments? thanks? email me!
eclipse_web@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
n/m

I figured it out. (and dont I feel dumb for it)

to answer my question, I guess && is the &quot;and&quot; operator
and || is the &quot;or&quot;

my problem was in the comparison statement

while ((iuserChoice< 1) || (iuserChoice >2)); Robert Carpenter
questions? comments? thanks? email me!
eclipse_web@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Correct, && and || are the logical AND and OR operators. There are also &, |, and ^, the bitwise operators for AND, OR and Exclusive-OR. :) Hope that this helped! ;-)
 
Hrm... what is a bitwise operator? Robert Carpenter
questions? comments? thanks? email me!
eclipse_web@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Logical operators consider values to be simply &quot;boolean&quot;, i.e. 0 is false, und !=0 is true (the actual value for &quot;true&quot; is 1, but C++ also considers any value !=0 as true in conditional expressions). Bitwise operators OTOH work on the individual bits in a field such as an integer, that is the operation is applied to each pair of bits in the two values, for eaxample (bit values) 1101 & 1110 = 1100, but 1101 && 1110 = 0001 (true). :) Hope that this helped! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top