Program closes down too soon

I´m doing a small exercise from a book I have. The purpose of it is to add together two numbers that the user chooses.

#include <iostream>
#include <limits>

using namespace std;

int Add (int x, int y)
{

cout << "Inside Add(), have received " << x << " and " << y << "\n";
return (x+y);
}

int main()
{
cout << "Now I am inside main()!\n";
int a, b, c;
cout << "Name two numbers: ";
cin >> a;
cin >> b;
cout << "\nCalling for Add()\n";
c=Add(a,b);
cout << "\nBack to main().\n";
cout << "c was " << c;
cout << "\nClosing...\n\n";

cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

return 0;
}

The problem is when I have chosen two numbers and press Enter the program is shutting down. Am I missing something?
Thanks.
cin >> leaves the last newline character in the stream
Hello. It is working fine for me here :)

Do you use visual studio? if you do press the Ctrl + F5(start without debugging) or add a system("PAUSE"); before your return 0

What Bazzy said. Fix it like this:

1
2
3
cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
cin.get(); //<- add this here! 
Working fine now. Thank you.
Topic archived. No new replies allowed.