Thread: This is basic C++

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    This is basic C++

    cout << "Hit q then enter to quit." << endl;
    char input;
    cin >> input;
    if(input == 'q') {} //what is this line saying here?
    // please I know this is stupid but it's confusing me at the moment
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    if(input == 'q')
    {
    return 0;
    }

    Uh...If you are going to do this, you will need to make the main() function an integer.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I was just wondering because I saw it on somebody else's codes and I just want to see, know what it means, because I am a little bit confused, I mean I know what it's doing but how would you say it in human terms, for xample " as long as.......then...."
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    ER
    Guest
    If the variable p has the value 'q' stored in it, then execute the code in the brackets.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    ER,

    You mean

    'if the variable input has the value 'q' then...
    Homer

    D'OH!

    mmmmmmmm... iterations

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    Re: This is basic C++

    Originally posted by elchulo2002
    cout << "Hit q then enter to quit." << endl;
    char input;
    cin >> input;
    if(input == 'q') {} //what is this line saying here?
    // please I know this is stupid but it's confusing me at the moment
    cout << "Hit q then enter to quit." << endl;
    displays quoted message on screen and, advances display one line, sets cursor to beginning of line

    char input;
    declares variable named input of type char

    cin >> input;
    reads in one character that user types and stores it in char variable input

    if(input == 'q') {}
    checks if user typed letter q, and does nothing if the user did.

    Why do that? I'd guess the program, or some part of it, ends right after that. The input probably pauses the program so that it doesn't flash by too quickly to see. It wouldn't really matter what the user typed, and they don't actually need the if statement; the program waits for the cin to occur, then continues. (It would check the if statement, but since it does nothing, just zips through it).

  7. #7
    Unregistered
    Guest
    so if the user doesn't input q then it keeps looping right?

  8. #8
    akira
    Guest
    it doesnt matter what the user types..
    if there is no more coding to the program then the progrom would end no matter what was typed..

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    but what if nothing was typed would it keep looping?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    Console programming is sequental based. Basically what akira said sums it up:
    if there is no more coding to the program then the progrom would end
    When you don't type in anything it doesn't loop, it just sits there, waiting for input.

  11. #11
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    elchulo2002


    The statement is not in a loop so it will not "keep on looping"

    The cin will wait until something is input from the kb (+return).

    The next statement is an IF statement, which will execute the instructions within the braces if the expression within the brackets is true, if not it will not execute the instructions within the brackets.

    Since there are no instructions within the brackets, the effect will be the same no matter what character is typed.

    The overall effect of this piece of code is that it will wait until the user types something and presses return (or just presses return for that matter), then continues with the program whatever that might be.
    if there is no more coding to the program then the progrom would end
    Homer

    D'OH!

    mmmmmmmm... iterations

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 11:38 PM