Thread: Return Integer Purpose??

  1. #1
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67

    Exclamation Return Integer Purpose??

    I'm still confused on the return integer's purpose. I also would like to know what in this code makes it so when you press the return key it exits the program. I would like to know what I would put in so when I press Esc key that the program exits.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
     cout<<"HEY, you, I'm alive!  Oh, and Hello World!\n";
    cin.get();
    
    return 1; <~~~WHAT!?? :confused: 
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I'm still confused on the return integer's purpose.
    Ok, how about these:

    1) It has no purpose.

    2) It's a secret code the Taliban use to contact Osama Bin Laden.

    3) It's a sign of the second coming.

    4) All functions require a return type.

    5) That's just the way it is.

    If you are new enough to the C++ language so that you don't understand what a 'return statement' is, it will have no pratical impact on your programming, and therefore you can forget about it--although you still have to include it in your programs. Once again, use this as a template for all your programs:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
         
          //Your code here
    
          return 0;  
    }
    Last edited by 7stud; 06-18-2005 at 06:44 PM.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I also would like to know what in this code makes it so when you press the return key it exits the program.
    cin.get();

    That says to read one char from the remaining input that was read in from the keyboard(cin=keyboard). Since no input was read in from the keyboard previously, the program waits until the user types something.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I would put in so when I press Esc key that the program exits.
    There is no way to do that with standard C++. However, this will work on windows:
    Code:
    #include <conio.h>
    
    ...
    
    
        getche();
    
        return 0;
    }

  5. #5
    Banned
    Join Date
    Jun 2005
    Posts
    594
    This might give you an idea or help you out.

    http://cboard.cprogramming.com/showt...&highlight=esc

    along with this


    http://www.asciitable.com

  6. #6
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    Code:
    return 0;
    this ends the program and returns control to your operating system. it aslo return the value 0 to the operating system. other values can be returned to indicate different end conditions for the program and can be used by the operating system to determine if the program executed successfully. typically, a zero indicates a normal end to a program and any nonzero value indicates an abnormal end. however, whether or not a nonzero return value can be acted upon will depend on the operating system concerned.
    nextus, the samurai warrior

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM