Hello everyone, super noob!

This is a discussion on Hello everyone, super noob! within the C++ Programming forums, part of the General Programming Boards category; Hey all, this is my first post on the forum, so let me know if i am in the wrong ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    5

    Talking Hello everyone, super noob!

    Hey all, this is my first post on the forum, so let me know if i am in the wrong spot. I am trying to teach myself C++ and have just started going through the tutorial here on the site, this is my first attempt at any type of programming. I have the Dev-C++ compiler which is working great, now I have a question, I just went through the 2nd tutorial on "if statements" and took the quiz thing here's the question

    1. Which of the following is true?
    A. 1
    B. 66
    C. .1
    D. -1
    E. All of the above

    now of course A is true, and that's what i went with, but apparently the answer is all of them? can anyone clear this up for me? i understand that each value has the ability to return a true statement, is that what the question is meaning?

    and also, in this line:

    !( 1 || 1 && 0 )

    when there's no parenthessis the 1 && 0 is looked at first equaling false, then 1 || 0 equaling true then !(1) equaling false, am i going about that right?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    In C++, 0 evaluates to false. Since none of the options are 0, they must all evaluate to true.

    when there's no parenthessis the 1 && 0 is looked at first equaling false, then 1 || 0 equaling true then !(1) equaling false, am i going about that right?
    Yes.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    True and false are BOOL data types. Apparently, it seems to be that 0 is false and everything else is true.
    BOOL data type actually returns a bit (i think so) and the true and false "checking" should be something like this:
    Code:
    if(intgr==0){
        //false
    }
    else{
        //true
    }
    You are right about those && and || things...
    Last edited by maxorator; 09-30-2006 at 01:22 PM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    awesome! thanks for the fast replies

    i was thinking that it's either 1 or 0, true or false, not true unless proven false, thanks for clearing that up!

    question 2

    1. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
    A. 10
    B. 9
    C. 0
    D. 1

    now when this is run it stops at 9, 0-9 is 10 equations BUT the final value is 9 i'm confused :S

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Now my test:
    Code:
    if(1 && 0 == 0 && 1)
    {
         //Nothing especial    
    }
    Say if it enters the if block or not.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by TiznaraN
    awesome! thanks for the fast replies

    i was thinking that it's either 1 or 0, true or false, not true unless proven false, thanks for clearing that up!

    question 2

    1. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
    A. 10
    B. 9
    C. 0
    D. 1

    now when this is run it stops at 9, 0-9 is 10 equations BUT the final value is 9 i'm confused :S
    It's quite easy actually.

    Int = 0
    Loop finishes 1st time, Int is now 1.
    Loop finishes 2nd time, Int is now 2.
    Loop finishes 3rd time, Int is now 3.
    Loop finishes 4th time, Int is now 4.
    Loop finishes 5th time, Int is now 5.
    Loop finishes 6th time, Int is now 6.
    Loop finishes 7th time, Int is now 7.
    Loop finishes 8th time, Int is now 8.
    Loop finishes 9th time, Int is now 9.
    and stops looping because int is now = 9 and not < 9...

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by siavoshkc
    Now my test:
    Code:
    if(1 && 0 == 0 && 1)
    {
         //Nothing especial    
    }
    Say if it enters the if block or not.
    I could say it easily if I would open my compiler, copy it there and press COMPILE.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    BUT the final value is 9
    No. It will be ten. Try this:
    Code:
    int x;
    for(x=0; x<10; x++) {} 
    cout << x;
    I could say it easily if I would open my compiler, copy it there and press COMPILE.
    The original question could be answered in that way too, smart boy.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    siavoshkc

    if(1 && 0 == 0 && 1)
    {
    //Nothing especial
    }

    0 = 0 is true so it would not block and would keep repeating?

    but as far as the quiz qustion, the answer is 10, and the final value of that statement is 9, 0-9 10 equations, but value of 9 right?

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    0 or "zero" is a non-number, thus C++ compilers regards it as false.

    The statement

    Code:
    bool b = true;
    bool c = false;
    
    cout << b << endl
            << c << endl;
    Would print 1 and 0. 1 is true. 0 is false

  11. #11
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    0 = 0 is true so it would not block and would keep repeating?
    The if statement and the following code between braces, and following else if, are all together called "if block", a code block.

    Would print 1 and 0. 1 is true. 0 is false
    It is just because cout is designed that way.
    Last edited by siavoshkc; 09-30-2006 at 02:38 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    ok so yes then if would enter the block, i thought i just read somewhere that when it doesn't enter into the if execution it's called a "block"

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    ok so i'm kinda pumped, someone give me a BEGGINER! quiz or something to test what i think i've learned so far or does anyone know of anywhere i can go to test my knowledge? newbie projects?

  14. #14
    Me
    Join Date
    Jul 2006
    Posts
    71
    Quote Originally Posted by TiznaraN
    ok so i'm kinda pumped, someone give me a BEGGINER! quiz or something to test what i think i've learned so far or does anyone know of anywhere i can go to test my knowledge? newbie projects?
    Just keep learning, that's all you have to do. You won't be able to make anything mind provoking until you learn a little more.

  15. #15
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    But if you like, solve this, enters or not?
    Code:
    int a = 41;
    int b = 20;
    if( (a || b)^ !(a- b) ^ ( (41 - a)  &&  !(a || false) && (b -  20 || true) )  )
    {
        //Nothing especial
    }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. super noob question
    By verbity in forum C++ Programming
    Replies: 6
    Last Post: 06-23-2007, 11:38 AM
  2. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  3. With super powers would you:
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-17-2003, 11:27 PM
  4. Post Super Bowl predictions here!
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 01-23-2003, 09:13 PM
  5. Which super hero(ine) are you?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-15-2002, 06:36 AM

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