Can anyone tell me why this is wrong?

I am writing a program that prompts the user of his DNA, prompts the user for the DNA of his relatives, then calculates the percentage of the match of the DNA of the user and the DNA of the relatives. For some reason, the program exits before it starts calculating the DNA match as well as the Display of percentage. Can someone tell me what is wrong with this code? I really need your help. Here is the function that matches the DNA of the user and the relatives as well as the main:

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
38
39
40
  void matchDNA(const string &userDNA,
	const string relativeDNA[], int percentMatch[],
	const int numRelatives)
{
	int match = 0;
	for (int i = 0; i < numRelatives; i++)
	{
		for (int iDNA = 0; i < 10; iDNA++)
		{
			if (userDNA[iDNA] == relativeDNA[i][iDNA])
				match++;
		}
		percentMatch[i] = match * 10;
	}

}

int main()
{
	int relatives = 0;
	string userDNA;

	getUser(userDNA);

	string relativeNames[50];
	const int numRelatives = getRelativeCount();

	getRelativeNames(relativeNames, numRelatives);
	string relativeDNA[50];

	getRelativeDNA(relativeNames, relativeDNA, numRelatives);

	int percentMatch[50];
	matchDNA(userDNA, relativeDNA, percentMatch, numRelatives);

	displayResults(numRelatives, percentMatch, relativeNames);

	return 0;
}
is userDNA[] guaranteed to have as many indexes as numRelatives?

Maybe somewhere your program is trying to access a memory out of location. That would be my primary suspect.

Maybe we can help better if you give us the other functions and sample input.
There should be 10 indexes for userDNA[] as well as numRelati
ves.

This is the other functions:

***
Last edited on
Take a close look at this line:

 
for (int iDNA = 0; i < 10; iDNA++)

And the line that sets match to zero should be inside the outer loop.
Sorry, I can't seem to find what is wrong with:

 
for (int iDNA = 0; i < 10; iDNA++)


I am not saying you are wrong. I legit don't know what is wrong since I am new to programming.
The condition (the middle part) should be iDNA < 10
As is, it creates an infinite loop since i starts at 0 and so is always < 10 in the inner loop.
Last edited on
YOU ARE A LIFE SAVER!!! It works! Thank you so much! I did not see that.
Topic archived. No new replies allowed.