Hello people, I've got a 2-d array, the first row has a string in each position, the second has a number in each position returned by a function that run on the strings.I run the mutatedstring function, run the matchmutated and put the values into the array, offspring times. Then I need to find the minimum number, and return the corresponding string. Could I use the min function for one row? How do I do this?

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 = [t][0];
		}
		// I need to find the minimum matchmutated in the array and return it's corresponding string

Thanks for the help!

Could you not scan the numbers in a loop find the minimum and store the position in a variable then output the string in that position?

How would I scan only one row of the array, while still keeping the strings that it corresponds to usable?
This is what I've done so far:

string mutated_chooser(string origmutated,string orisentance int offspringnumber){
	int array [2][offspringnumber];
	int min;
		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];
		for (j=0; j=offspingnumber; j++)
		{
			if (array[1][j] < min) 
			{min = a[1][j];} // set the smallest value of the arra
		}
	//now i'm usure how to get the string back from the minimum matchnumber

if you create a variable say posvar
line 16

{min = array[1][j];posvar=j;}

then

cout<<array[0][j];

sorry meant

cout<<array[0][varpos];

There's an error coming up saying that "c++ does not support variable size arrays", is there an easy way out of this? Or do I have to use something like vectors (not too sure how to use them)?

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.