Your pause function does not quite do what you think it does.
Lets imagine reading some data from the input stream, like this:
int i;
std::cin >> i;
The user types in a number, and hits return. operator>>
will pull characters out of cin
until it finds one that cannot be converted to an int
, which it will leave there. In the case of normal user input, the character that is left on the stream is the newline (\n
).
When you come to call your pause
function, you try to do this:
std::cin.ignore()
which will ignore one single character on the input stream. Only there's a stray \n
on the stream from the last time someone entered some data! So pause
returns immediately.
You need to take steps to clean your input stream after use, perhaps by doing this each time after you've used std::cin >> whatever
.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
This will drop everything after the last valid input character to the final newline. Your pause function will likely work a little better after that.
Alternatively, instead of using >>
, you could use getline
, which is designed to deal with newline-terminated text strings.
std::string stuff;
std::getline(std::cin, stuff);
if (stuff.length() > 1)
std::cout << "Easy, tiger.\n";
getline
removes the trailing \n
for you, which will also help your pause
function work better.