c++ solution works