The reason is that the input buffer is not flushed. Remove num++
, add cin.ignore(100, '\n');
after cin >> num;
.
ok i kind of thought that might be the case. would cin.sync() work also?
That seems like a big problem with C++, i usually find myself having to flush the input buffer alot.