C++ solution to problem 4. Needs work.