WHAT DO YOU MEAN, in tutors?

This is a discussion on WHAT DO YOU MEAN, in tutors? within the C++ Programming forums, part of the General Programming Boards category; Hi, i thinked i will laern from the tutors from this site, so i read 2 first lessons until now! ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    99

    WHAT DO YOU MEAN, in tutors?

    Hi,
    i thinked i will laern from the tutors from this site, so i read 2 first lessons until now!
    But in second, I didn't get some things.
    At the end you have this:
    NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE. For example, NOT (1) evalutes to 0, and NOT (0) evalutes to 1. NOT (any number but zero) evaluates to 0. In C and C++ NOT is written as !. NOT is evaluated prior to both AND and OR.

    AND: This is another important command. AND returns TRUE if both inputs are TRUE (if 'this' AND 'that' are true). (1) AND (0) would evaluate to zero because one of the inputs is false (both must be TRUE for it to evaluate to TRUE). (1) AND (1) evaluates to 1. (any number but 0) AND (0) evaluates to 0. The AND operator is written && in C++. Do not be confused by thinking it checks equality between numbers: it does not. Keep in mind that the AND operator is evaluated before the OR operator.

    OR: Very useful is the OR statement! If either (or both) of the two values it checks are TRUE then it returns TRUE. For example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || in C++. Those are the pipe characters. On your keyboard, they may look like a stretched colon. On my computer the pipe shares its key with \. Keep in mind that OR will be evaluated after AND.

    It is possible to combine several boolean operators in a single statement; often you will find doing so to be of great value when creating complex expressions for if statements. What is !(1 && 0)? Of course, it would be TRUE. It is true is because 1 && 0 evaluates to 0 and !0 evaluates to TRUE (ie, 1).

    Try some of these - they're not too hard. If you have questions about them, feel free to stop by our forums.
    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

    If you find you enjoyed this section, then you might want to look more at Boolean Algebra.
    Can i see example of these things in open source code becausei didn't get how we are writing them,
    thanks

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Code:
    int num1, num2;
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;
    // Do something if all are positive
    if( num1 >= 0 && num2 >= 0 )
    {
        // Do stuff
    }
    // Do something if only one of numbers is positive
    if( (num1 >= 0 && num2 < 0) || (num1 < 0 && num2 >= 0) )
    {
        // Do stuff
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Try to think about the logic....

    The fact that these operators "evaluate" to one or zero might add to the confusion. Try to think TRUE or FALSE, rather than one & zero.

    But, you should know that zero is FALSE, and any other number is TRUE. This means that I can write if (n - 5)... And, I can write if(n)...

    some simple logic exampes:
    If the user presses [ENTER], then do something. If the user's name is NOT "Doug", then exit.

    Or, "If color is blue OR green, then..." "If animal is a dog, AND it's hair is NOT blue, then..."


    Most online tutorials are very condensed. I recommend that you get a book, and use more than one online source. Here's another tutorial.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    ok i think i get some things
    I WISH I KNew c++ LIKE YOU GUYS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array [Wayy less complicated than other posts]
    By Robert_Sitter in forum C++ Programming
    Replies: 6
    Last Post: 10-30-2005, 08:39 PM
  2. Any Visual C++ Tutorials?
    By Grayson_Peddie in forum Windows Programming
    Replies: 5
    Last Post: 05-12-2002, 11:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21