Solves Problem 11 in C++ and fixes corner case in Problem 8