When allocating an array the size needs to be constant when allocated on the stack. You can allocate it on the heap to use a non constant array size like so:
Note: this program shouldn't even compile. Array sizes must be compile time constants in C++.
Exactly what I said, your program shouldn't compile. You are using a non-constant when creating your array, that is not allowed in C++. In C++ array sizes must be compile time constants, your size is not a constant.