Menu

run window closes when pressed "enter" key

2007-07-08
2012-09-26
  • Nobody/Anonymous

    Hi, I am learing C++ now. So, everytime i run any program such as follows:

    include <iostream>

    using namespace std;

    int main ()
    {
    int i;
    cout << "Please enter an integer value: ";
    cin >> i;
    cout << "The value you entered is " << i;
    cout << " and its double is " << i*2 << ".\n";
    return 0;
    }

    after i enter the value in the first line and press "Enter", the run window dissapear. It supposed to calculate the value in the second line. What am i doing wrong here? Please help me with this. Thanks
    Bill.

     
    • Nobody/Anonymous

      One way to insert a pause in your program, as it is written,
      is to insert these 3 lines ...

      cout << "\nPress 'Enter' to continue ... " << flush;
      cin.sync(); // to 'eat up' any characters in the cin input stream
      cin.get(); // To wait for 'Enter' key to be pressed

      If you had done a little searching, you might have discovered this for you self.
      'Searching', using appropriate key words, is an important skill to acquire too.

       
    • Nobody/Anonymous

      It does, but after calculate and show the second line if finish, so You can't see the result.
      Try to insert a pause before the program exit (the return).

      Old Newbie

       
    • shipu

      shipu - 2007-07-08

      how do i insert a pause in above program? Any idea?

       
      • Nobody/Anonymous

        Read this forum, you lazy lame brain!

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.