Completed probld problem 2 in c++