while loop exit

I intend for an 'n' to stop the program. When an 'n' is entered, the last line is contiuously displayed. How do I stop this while loop?

#include <iostream>
using namespace std;

void main()
{
int X=0,Y=0,T=0;
while(X != 'n')
{
cout << "Enter Integeers ==> ";
cin >> X;
cin >> Y;
T = X+Y;
cout << T;
}
}
'n' is a char type, whereas X is an int type. This causes std::cin to fail, and because you never check for cin.fail(), your program continuously loops. If this was an assignment, I'm pretty sure that n was meant to be a numeric constant (like -1 or 0) of your choice.
Topic archived. No new replies allowed.