The extraction operator >> leaves whitespace in the stream. So your program runs all the code as it should, then when it reaches the cin.ignore() that you have to keep the console running, the whitespace that was left in the stream gets ignored and your program closes.
Because you instert nr + ENTER or '\n' when you enter your number.
So the cin.ignore reads your newline, which you entered at cin >> n; by pressing ENTER.
You have to clear your buffer first or to use another cin.ignore.
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
As i know the first parameter of cin.ignore(..) method stands for maximum number of characters to ignore, but if you put that one mentioned above (maximum number of characters in a specific type - here integer) there won't be any input limitand the method passes all characters till its equal to the 2ndparameter - here "/n")
Tevsky and jmc already wrote about that
I think you can use cin.ignore(2); That should work fine in your example