C++ exercise 4