// Score Rater 2.0
// Demonstrates an else clause
#include <iostream>
usingnamespace std;
int main()
{
int score;
cout << "Enter your score: ";
cin >> score;
if (score > 500)
cout << "\nYou got over 500. Nice score.\n";
else
cout << "\nYou got 500 or less. Nothing to brag about.\n";
return 0;
}
The consol pops up and it works great. Untill i write a number (as im suppost) in the consol. Then it closes down really quick. No error message or anything.
I quess its something with the compiler. That i have to change some settings somewhere or something like that. Or maybe its the code. But i dont think so.
This have happen in some other programs i have made. Where I have to type something in (A number, letters, etc).
I type the "cin.ignore( numeric_limits<streamsize>::max(), '\n' );" in right before the "Return 0;" - Is that correct?
Yes
And still, when it says "Enter Your Score" and i press "500" it closes down.
The problem should be that you are using >> to get input and it leaves the last newline character.
There are many ways of removing it, one is calling cin.ignore another time.
If you instead want to get input in a safer way, read this article: http://www.cplusplus.com/forum/articles/6046/ (In this way you would need to call cin.ignore only once)