Thanks you for the response. Adding the if statement before the push_back statement worked.
I'm still a little confused. When using a while loop, does the loop break immediately when the while loop condition becomes false, or will it continue until the end of the block, and just not loop again?
Yes, with a little tinkering I realized that I didn't fully understand while loops. I was under the false impression that they would break immediately when the condition became false. Thanks for helping to clear up my confusion.