I ran it and it works ok. In response to the prompt you enter a, then a space, then b, then a carriage return. You can also respond a, carriage return, b, carriage return. Your comments indicate that you expect it to do something after you enter a. What it's doing is waiting for b.
Good Luck
murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1
>Since it seems like this is just gonna go one for ever saying "it works for me" someone just lock this thread.
Maybe you should be more specific than "it doesn't work". It sounds like you're experiencing the first problem that most Dev-C++ users ask here, where the output window closes when the program terminates, and you don't see the complete output. Try this:
#include <iostream>
#include <limits>
using namespace std;
int main()
{
cout << "Please enter 2 numbers to be added ";
int a;
int b;
cin >> a;
cout << "\n num1: " << a << endl;
cin >> b;
cout << " num2: " << b << endl;
cout << " a + b = " << a + b << endl;
cout << "Press the enter key to exit";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
return 0;
}
>cin.ignore(cin.rdbuf()->in_avail() + 1);
This isn't strictly guaranteed to do what you think it's doing, for several somewhat advanced reasons that I'm not terribly interested in explaining right now. But you can treat it like cin.sync() and avoid it in favor of the above example most of the time.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401