Implement triangle number utility code in C++