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??

Edited by WaltP: Added CODE Tags -- learn to use them.

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by ik1610

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

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

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

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

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]` .

Or you can use dynamic arrays.

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
:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.