factors is a variable length array, which is a non-standard language feature. You could either create a fixed size array that is as large as you will ever need, or use a container like std::vector:
Code:
std::vector<int> factors(halfVal);
This should also zero initialise the elements of factors.