Help with Dev C++!

This is a discussion on Help with Dev C++! within the C++ Programming forums, part of the General Programming Boards category; I gots a prob. Whenever I run the program, the program pops up and then dissapears! Here's the code: Code: ...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Help with Dev C++!

    I gots a prob. Whenever I run the program, the program pops up and then dissapears! Here's the code:
    Code:
    #include <iostream.h>
    #include <string>
    #include <windows.h>
    int main()
        {
        std::string plant;
        std::string glint;
        cout << "The world is about to be destroyed. You are in a futuristic spy base." << endl;
        cout << "You will soon go on a mission to save the world. In the corner of the room," << endl;
        cout << "you see a plant. The door is to the north and the basement is down." << endl;
        std::string firstroom;
        cin >> firstroom;
        if(firstroom == "x plant")
                     {
                     cout << "As you examine the plant, you spot a glint of silver in the soil." << endl;
                     cin >> plant;
                     }
        if(plant == "x glint" || "get glint")
                     {
                     plant:
                     cout << "You pick up the glint. It is a keycard to the NETWORK." << endl;
                     int getglint;
                     getglint = 1;
                     cin >> glint;
                     }
        system("pause");
        return 0;
        }
    Yup
    Last edited by gcn_zelda; 03-18-2003 at 05:39 PM.

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Start-->Run-->Cmd/Command--> C:\>YourProg.exe

  3. #3
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    thanks, but...

    it didn't work

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Everyone has this problem. iF you do a search you will find other solutions. i use this.

    Code:
    #include <conio.h>  // include this header file
    #include <iostream.h>
    #include <string>
    #include <windows.h>
    
    int main()
    {
    std::string plant;
    std::string glint;
    cout << "The world is about to be destroyed. You are in a futuristic spy base." << endl;
    cout << "You will soon go on a mission to save the world. In the corner of the room," << endl;
    cout << "you see a plant. The door is to the north and the basement is down." << endl;
    std::string firstroom;
    cin >> firstroom;
    if(firstroom == "x plant")
    {
    cout << "As you examine the plant, you spot a glint of silver in the soil." << endl;
    cin >> plant;
    }
    if(plant == "x glint" || "get glint")
    {
    plant:
    cout << "You pick up the glint. It is a keycard to the NETWORK." << endl;
    int getglint;
    getglint = 1;
    cin >> glint;
    }
    getch();// add this line it, it waits for any keystroke from user!!!!
    return 0;
    }

    Just add the header file and that getch() line in front of your return 0 and it should work. IF not look around and find other ways that people do it.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Actually, you don't need to use a not-standard function and library like getch() from conio. You just need to pause your program, a good way to do it is to add before the 'return' of your end function this snippet:
    Code:
    system("PAUSE");

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    help!

    now when i do it, it just says
    Press any key
    when i compile it.

  7. #7
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    He says "Press any key to continue..." and you should press any key to exit from the program.

  8. #8
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    right, but thats all it says and it doesn't run the actual program

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    Vber you are correct its not good to use non-standard. However if you look closely at his original program thats what he used. System pause and it didnt work thats why he is asking for help.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    yes, but pause must be in all caps to work i believe. you could use std::cin.get(); before return; and if it doesn't work:
    Code:
    std::cin.ignore();
    std::cin.get();
    add these two lines before the return statement.

    edit: gcn, try placing it after code, and before the return statement. if you did, and that is the output you get with the above mentioned methods, then that is weird. at that pt. you may want to post code again.

  11. #11
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > yes, but pause must be in all caps to work i believe.
    Actually that works just fine.

    > Whenever I run the program, the program pops up and then dissapears! Here's the code:
    That's very weird considering that your code asks for input almost immediately.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    It doesn't have to be in caps. All system() does is send that string to the command line. It can be in mixed-case for all it cares.

  13. #13
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    >
    It doesn't have to be in caps. All system() does is send that string to the command line. It can be in mixed-case for all it cares.
    <
    Thanks for echoing me.

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    34
    #using namespace std


    with your cin lines:
    "firstroom"
    "glint"
    "plant"
    These are declared as strings



    '

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 12:05 AM
  2. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 07:43 PM
  3. openGL programming - From MSVC++ to Dev C++
    By WDT in forum Game Programming
    Replies: 3
    Last Post: 03-08-2004, 07:47 PM
  4. openGL programming - From MSVC++ to Dev C++
    By WDT in forum Game Programming
    Replies: 1
    Last Post: 03-08-2004, 04:19 PM
  5. DEV C++ Limitations?
    By Kirdra in forum Game Programming
    Replies: 3
    Last Post: 09-09-2002, 09:40 PM

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