#1
  1. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15

    (noob) what button to press =D


    hi,

    i'm going through a book and it gave this example. (w/o cin.get())

    Code:
        const int inches_per_foot = 12;
        const int feet_per_yard = 3;
        
        int yards = 0;
        int feet = 0;
        int inches = 0;
        
        // read the length from the keyboard
        cout << "Enter a length as yards, feet, and inches: ";
        cin >> yards >> feet >> inches;
        
        // output the length in inches
        cout << endl
            << "Length in inches is "
            << inches + inches_per_foot * (feet + feet_per_yard * yards)
            << endl;
        return 0;
        cin.get();
    so i type the 3 numbers.

    but what do i press to see the result? =D if i press enter it closes.

    i had to use cin.get() cause the thing closed right away.

    i'm using Dev C++ 4.9.8.0
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    12
    Just type yards, feet, inches, and hit enter. It shoudl output from there. :)
  4. #3
  5. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    nope. it closes the window
  6. #4
  7. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0
    Ah, I think I know what happening.Pressing enter isn't closing the program, but by default when you launch a command window program without using the command prompt it will close automatically when it finishes running. Visual C++ automatically pauses the application when it's done, but for your compiler insert this line before the return statement:
    PHP Code:
    system("PAUSE"); 
    Hope that works.
  8. #5
  9. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    that did the trick =D thanks
  10. #6
  11. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0
    Heh, actually it just so happens I was writing a console application for one of my classes earlier this week and I ran into the exact same problem :D
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,154
    Rep Power
    2222
    This question is perhaps the single most asked one here. I think we've all fallen victim to it. Now we have one more person to educate the rest.
  14. #8
  15. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    =)
  16. #9
  17. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Actually you have the return 0; before the cin.get();
    It never pauses because of this.
  18. #10
  19. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    what u mean?
  20. #11
  21. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Code:
        cout << endl
            << "Length in inches is "
            << inches + inches_per_foot * (feet + feet_per_yard * yards)
            << endl;
        return 0;  // <-- this is executed
        cin.get();  // <-- before this
    The return 0; statement will exit the program before the cin.get() statement gets a chance to execute.
  22. #12
  23. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    it didnt exit until i pressed enter

IMN logo majestic logo threadwatch logo seochat tools logo