Problem with for-loop

Hi everyone

I have to created an array in which I store the coordinates of n target (n is determinate when the user calls the program).
Than I want to compute the distance from each target to each target. So from target 1 to target 2, store the number ob steps, then form 1 to 3 and so on. Therefore I tried to use two "for"-loops to iterate through the array.

So my approach was first store the x and y Coordinates in a two dimensional array. So x in the first column y in the second.

Then I wanted to read the coordinates from the array and pass it to an function, which calculates the number of steps. But here's my problem: The two for-loops I use to iterate through the array seem don't work as planed. The first loop gets the target, where I'm starting from, the second loop should go to the other targets and get the coordinates.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
int main( int argc, char *argv[] ) {

   unsigned int width = atoi( argv[1] );
   unsigned int height = atoi( argv[2] );
   unsigned int agents = atoi( argv[4] );

   unsigned int testarray[agents][2];	
   unsigned int xstartcoord;
   unsigned int ystartcoord;
   unsigned int xendcoord;
   unsigned int yendcoord;
	
   time_t t;
   time(&t);
   srand((unsigned int)t);
	
   for( int i=0; i<agents; i++)
   {
      testarray[i][0]=rand() % width + 1;
      testarray[i][1]=rand() % height + 1;
   }
	
   for(int i=0; i<(agents-1); i++)
   {
      xstartcoord=testarray[i][0];
      ystartcoord=testarray[i][1];
      
      for(int j=(i+1); j<(agents-2); j++)
      {
         xendcoord=testarray[j][0];
	 yendcoord=testarray[j][1];
         stepcount=Test(xstartcoord, ystartcoord, xendcoord, yendcoord);
      }
   }

   return 0;
}
Last edited on
Line 7 is not valid C++. array sizes must be known at compile time.
Topic archived. No new replies allowed.