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

Recommended Answers

All 7 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.