1. You are missing a subscript somewhere.
2. The size is unknown for something somewhere.
3. Your syntax is bad - contains an error somewhere.
Why are you the age that you are?
You tell us, then we will all know.......
How many people do know that are telepathic?
Is my sister taller than you?
Cliches until the cows come home.
The sum of apples and cars equals how many houses?
At what point does a question become so vague that no one can find an answer?
Have you heard of Google or wiki, or read any tutorials, a text book, or not slept through your lecture?
Have you actually written any code, or is this you star gazing about what future errors you might have?
Consider thinking about how to ask questions effectively.
Have we reached a new depth of Y-Gen laziness? (sorry for the obvious mass generalisation)
Sorry, couldn't help myself for a bit of comedy - silly questions, silly answers :D .
No idea about your problem unless you show us the code.
Make sure you use code tags - use the <> button on the right under formatting.
cout<< "Insert the maximum number of hops of the routing algorithm used :";
cin>> num_of_hops;
cout << endl << "number of paths : " << num_of_paths << endl;
int path_matrix[][];
path_matrix[num_of_paths][num_of_hops + 1];
float path_length[]; // The total length of each path
path_length[num_of_paths];
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'a' : unknown size
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
i am unable to execute the array if the subscript value is obtained at the run time..i.e the value of the array index is dynamic and depends on the users input........
i am unable to execute the array if the subscript value is obtained at the run time
That's right, the array size must be a constant known at compile time.
Just so you know for future reference about arrays:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//better to do this than use magic numbers in the code
constunsignedint NumOfPaths = 10;
constunsignedint NumOfHops = 10;
int path_matrix[][]; //does not work unless there is an initialisation list in braces
//because the compiler counts how things there are
path_matrix[num_of_paths][num_of_hops + 1];
int PathMatrix[NumOfPaths][NumOfHops]; //now it's ok size and type is known
float path_length[]; // The total length of each path
path_length[num_of_paths]; //combine these 2 lines
float PathLength[NumOfPaths]; //Ok - size and type known
You need to use some other STL container which automatically gets larger (they have push_back and insert functions), if you want to set the size at run time.
#include <iostream>
int main()
{
int count;
std::cin >> count; //Get size of an array
int* x = newint[count]; //Create new array of size count and make x point to it
//Initializating all array elements to zero
for(int i = 0; i < count; ++i)
x[i] = 0;
//Setting first and last array elements to 6 and 2 respectively
x[0] = 6;
x[count-1] = 2;
//outputting array
for(int i = 0; i < count; ++i)
std::cout << x[i] << '\n';
std::cout << std::endl;
return 0;
}