Thread: How do I..

  1. #1
    n00b0ne
    Guest

    How do I..

    How do I do so the program dont automatically closes after its been run? Reply greatly appreciated

  2. #2
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    Simplest thing is to just put in something like

    Code:
    int a;
    cin >> a;
    The program will then wait for you to enter something before exiting.

  3. #3
    n00b0ne
    Guest
    Ok, I tryed to make a little thing in dos modus


    code:

    #include <iostream.h>
    #include <stdlib.h>

    int main()
    {
    int age;
    cout<<"Please write your age"<<endl;
    cin >> age;
    int loc;
    cout<<"Please write where you live"<<endl;
    cin >> loc;
    cout<<"you are "<<age<<" years old, and you live in "<<loc<<endl;
    int exit;
    cin >> exit;
    return 0;
    }


    It doesnt seem to work at this point, it close fast just like earlier, can you see why?

  4. #4
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    Well I can't see why it should be doing that, but you can put,

    Code:
    system ("pause");
    in before the return statement.

  5. #5
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    I just tried your example (without system ("pause")) and it works fine.

    I assume you realise that you are using an integer to hold the value of the user input in response to the question about where the user lives. If you actually want them to write the name of their town or something you should use a character string.

  6. #6
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    OK, couple of things here.

    Firstly:
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    should be:
    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    Second, you're asking for location as an integer, you should learn about the char type and about arrays.

    Lastly read the FAQ on how to pause your program.

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    n00b0ne
    Guest
    thankz all

Popular pages Recent additions subscribe to a feed