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.
using namespace std;
int Add (int x, int y)
cout << "Inside Add(), have received " << x << " and " << y << "\n";
cout << "Now I am inside main()!\n";
int a, b, c;
cout << "Name two numbers: ";
cin >> a;
cin >> b;
cout << "\nCalling for Add()\n";
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' );
The problem is when I have chosen two numbers and press Enter the program is shutting down. Am I missing something?
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
Working fine now. Thank you.