working, first c++ solution