## ik1610

Hello!
I am having a problem with the following line of code:

``````int temporary = theMessage.size();
int numberOfColumns;

if (temporary%3 == 0)
numberOfColumns = temporary/3;
if (temporary%3 == 1)
numberOfColumns = (temporary + 2)/3;
if (temporary%3 == 2)
numberOfColumns = (temporary + 1)/3;
cout<<numberOfColumns<<endl;

int theNumbersOfTheMatrix[3][numberOfColumns];``````

theMessage is a string of modifiable length.
Until the point
cout<<numberOfColumns<<endl;
it works but then it says that the expression should have a constant value. Could somebody help me??

## WaltP 2,905

numberOfColumns is not a "constant value" so you can't declare your array the way you did.

## ik1610

so how can i make a matrix of a fixed number of columns but with number of rows the length of a string?

## WaltP 2,905

Why not make the array large enough to hold the largest message you expect?

## ik1610

because its a matrix and i have to use it in a multiplication...

## WaltP 2,905

because its a matrix and i have to use it in a multiplication...

Yeah, so?

If you have a matrix defined `int matrix[100][100]` and you only load the values from `matrix[0][0]` thru `matrix[19][29]` , why would the rest of the matrix be used for multiplication? Just use the part that's loaded, thru `matrix[20][30]` .

## elexender

Or you can use dynamic arrays.

## ik1610

i could not do this because its an encryption decryption thing... i figured it out though by using dynamic memory and defining the matrix as

int * MessageMatrix[3];
for (int i = 0; i < 3; i++)
MessageMatrix = new int [numberOfColumns];

Thanks anyway
:)