Trying to solve Treasure in C++