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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
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
how do i insert a pause in above program? Any idea?
Read this forum, you lazy lame brain!