First, you don't want your instructor to know that you simply copied the code from this web page . Getting assistance by using the page is one thing.... basically plagiarizing the code is another altogether. However, the output is correct, and the program does work.
The reason it is likely "just closing" is because you are running this through a GUI of some kind, that launches the code, and exits (hence, closing the otuput window). You can run this through a command line, or put a cin.ignore() just before the return 0; (which you don't have, but should have as the last line before the ending }). If one cin.ignore() doesn't work, try two.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215