attempting to solve in c++.