Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: n00b C++ question : Shuting out withought displaying all of program

  1. #1
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    n00b C++ question : Shuting out withought displaying all of program

    Hey guys, I am starting C++ and am having a small problem. I know it is somthing simple but can't figure out what. The program closes out after you enter the width instead of displaying the area.

    heres the code:
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int length, width;
        cout<<"Enter the length of the object:";
        cin>>length;
        cout<<"Enter the width of the object:";
        cin>>width;
        cout<<"The area of the object is ";
        int area;
        area= length*width;
        cout<<area;
        cin.get();
        
        return EXIT_SUCCESS;
    }
    Also I am using Bloodshed C++ Beta 5. I would like to use the previous full version so that I know there are no bugs in the compiler. If any one could point me to it I would be thankfull

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2008
    Location
    Somewhere that is shorter to write than "In the gloomy shadows of my personal namespace"
    Posts
    10,725
    Blog Entries
    2
    Rep Power
    90

    Re: n00b C++ question : Shuting out withought displaying all of program

    Oh, one of the most annoying things in the world, that sh*t..

    Code:
    cin.get();
    I have also very much struggled/been annoyed by this. It seems to work for some people and not for others, I'm not sure why. What I have figured is that there are characters "waiting" in the input buffer, which are read by cin, and then -> goodbye. I might be wrong, but this seems to be the problem. I solved this by creating a "FlushInput" function which... flushes the input buffer!

    I could post the code and some examples to how I use it, if you want, assuming you are using Windows.

    A much simpler way of achieving basically the same result (wait for user input) is the

    Code:
    system("PAUSE");
    Try it.
    Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  4. #3
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: n00b C++ question : Shuting out withought displaying all of program

    The system pause worked. Thanks. Man thats going to get annoying fast

  5. #4
    Join Date
    May 2008
    Posts
    2,126
    Blog Entries
    1
    Rep Power
    33

    Re: n00b C++ question : Shuting out withought displaying all of program

    Bloodshed isn't a compiler.

  6. #5
    Join Date
    Jul 2008
    Location
    Somewhere that is shorter to write than "In the gloomy shadows of my personal namespace"
    Posts
    10,725
    Blog Entries
    2
    Rep Power
    90

    Re: n00b C++ question : Shuting out withought displaying all of program

    Right MeTh0dz. Bloodshed makes the IDE, and it comes with MinGW (GCC) as a compiler. I'm not sure if this annoying little problem is related to the compiler.... Is anone using e.g. borland? Same problem there? On borland I think you can also use "getch()" - which is supposed to work... IDK..
    Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  7. #6
    Join Date
    May 2008
    Posts
    2,126
    Blog Entries
    1
    Rep Power
    33

    Re: n00b C++ question : Shuting out withought displaying all of program

    Borland is ****.

    Just include conio.h, and you can use getch().

  8. #7
    Join Date
    Jul 2008
    Location
    Somewhere that is shorter to write than "In the gloomy shadows of my personal namespace"
    Posts
    10,725
    Blog Entries
    2
    Rep Power
    90

    Re: n00b C++ question : Shuting out withought displaying all of program

    I've never tried borland, so I can't really comment on that one. But if anybody uses it, it would be interesting to know if they had the same problem.

    I don't think I have conio.h on my computer.. But I doubt I'm going to need it anyway..
    Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

  9. #8
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: n00b C++ question : Shuting out withought displaying all of program

    Methodz way works great. Let me rephrase my other question, where can I get a non beta version of bloodshed C++. I have visual C++ but don't want to use it.

  10. #9
    Join Date
    Nov 2006
    Location
    Kosovo
    Posts
    448
    Rep Power
    28

    Re: n00b C++ question : Shuting out withought displaying all of program

    I used to open the command prompt and then run the compiled program by typing its location so the window wouldn't close, lol

  11. #10
    Join Date
    May 2008
    Posts
    2,126
    Blog Entries
    1
    Rep Power
    33

    Re: n00b C++ question : Shuting out withought displaying all of program

    Bloodshed DevCpp is no longer in development.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. n00b Object Scope question
    By belch85 in forum C# Programming
    Replies: 5
    Last Post: 11-23-2010, 06:36 AM
  2. n00b question
    By bajerocks in forum C and C++
    Replies: 3
    Last Post: 04-04-2010, 11:12 AM
  3. Replies: 3
    Last Post: 01-15-2010, 11:54 PM
  4. n00b problem with an editor
    By WIlfred86 in forum Python
    Replies: 4
    Last Post: 04-04-2009, 03:38 PM
  5. n00b class question
    By MerakSpielman in forum C and C++
    Replies: 15
    Last Post: 02-20-2008, 08:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts