Unsure how to use 2-d array

Hi guys, I have a 2-d array, one row has a string for each position and the other row has a number, i'm trying to find the minimum number in the second row and return the string that is in the same column. I'm not sure how to write this.

This is what I have already

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
string mutated_chooser(string origmutated,string orisentance int offspringnumber){
	int array [2][offspringnumber];
			for (int t=0; t=offspringnumber-1;t++){
 
			string newmutated=mutatedstring(origmutated);
			newmutated= array [0][t];
			int matchmutated= match(orisentance,newmutated);
			matchmutated=[1][t];
		}
 
	int min = array[1][j];// is this correct syntax for finding the minimum of only one row?
		for (j=0; j=offspingnumber; j++)
		{
			if (array[1][j] < min) 
			{min = a[1][j];} // set to the smallest value of the array
		}
	//now i'm usure how to get the string back from the minimum matchnumber 


First of all is the syntax I have already written correct?

If I just set a variable min to be equal to the smallest number of the row, how will I retrieve the string that it corresponds to?

Thanks a lot guys.
int min = min < array[1][j] ? min : array[1][j]
Last edited on
So you want the column index of the minimum number:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string mutated_chooser(string origmutated,string orisentance int offspringnumber){
	int array [2][offspringnumber];
			for (int t=0; t=offspringnumber-1;t++){
 
			string newmutated=mutatedstring(origmutated);
			newmutated= array [0][t];
			int matchmutated= match(orisentance,newmutated);
			matchmutated=[1][t];
		}
 
	int min = array[1][j];// is this correct syntax for finding the minimum of only one row?
	int col_idx = 0; // This is the index
		for (j=0; j=offspingnumber; j++)
		{
			if (array[1][j] < min) 
			{min = a[1][j]; col_idx = j;} // set to the smallest value of the array and the index of that column
		}
	//now 'col_idx' contains the index of the minimum number  
Thanks for the help. Another thing, when I try to compile it comes up witht the error: ISO C++ forbids variable size array "array". Why is this?
The size of the array has to be known at compile time. That means that the number you use to specify the size of the array has to be a compile time constant. In you code offspringnumber is not a compile time constant. You can solve this by dynamically allocate the array using new or use some kind of container like std::vector that handles the allocations and other things for you.
Topic archived. No new replies allowed.