Why do i need to use cin.get twice?

Hey guys, i was writing a very simple program and came a across an problem. In order to stop my program from closing i had to use cin.get () twice? Is this normal ? here is my code -

int main()
{
int a;
int b;
int sum;


cout << "To start this addition calculator, please enter a number!" << endl << endl;

cin >> a;

cout << "Now enter another number !" << endl << endl;

cin >> b;

sum = a + b;

cout << "The sum of those two numbers is " << sum << endl << endl;

cout << "This program was created by Omar Ismail" << endl <<endl;

cout << "Press enter to continue..." ;



cin.get ();
cin.get ();

return 0;
}












Oh and also, don't post alternatives to cin.get. Thanks :)
I tried you program and it seems you are right.

Then, I did:

1
2
3
4
char c;
cin.get (c);

cout << (int)c <<  endl;


And this writes 10 which it's a newline.

Likely, the last number you wrote, you wrote it and then press enter. So, it seems that you are getting that newline. So, for this you need cin twice.
Topic archived. No new replies allowed.