Problem 3 solved (C++)