From what I've seen, most people use system("pause") which will wait for a key press. The reason it closes immediately is because it runs the commands then returns, ending your program. Windows then closes the command window because it is finished.
Ok, that makes sense. May I ask, where do I insert the
system("pause")
line in that code? I would guess just before the return, but trying that gave me errors. I really am a rank beginner, can you specify the exact code I need to insert?