working c++ soln