Here is a textbook example from Absolute C++ by Walter Savitch:
I tried a different version but got an error, so I tried typing out the code exactly: