Compare Two Arrays

I'm trying to make a program where two arrays with 10 digits each are compared to one another. The program will then print out the number of matches. So far my program cannot find any matches. I think I have one or more counters messed up or in the wrong place. Anyone able to see where I made mistakes?

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
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	int matches = 0,
		num1,
		num2,
		i = 0,
		arrayReference1 = 0,
		arrayReference2 = 0;

	
	int firstArray[] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 0};
	int secondArray[] = {1, 22, 3, 44, 5, 66, 7, 88, 9, 10};

	
	while (i <= 9, i++)
	{
	num1 = firstArray[arrayReference1];
	num2 = secondArray[arrayReference2];

		if (num1 == num2)
		{
			matches++;
			arrayReference1++;
		}

		else
			arrayReference2++;
	}

	cout << "You have this many matches: " << matches;
	cout << endl;

	system("PAUSE");
	return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	int matches = 0,
	
	int Array1[] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 0};
	int Array2[] = {1, 22, 3, 44, 5, 66, 7, 88, 9, 10};
	
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			if(Array1[i]==Array2[j]){				
				cout << "Match " << ++matches << ": " << Array1[i] << endl;
			}
		}
			
	}

return 0;
}
Thank you. That did give me the number of matches [4], but now I would like to print out all 10 numbers for both arrays. Is there a way to do that at the end? Or do I have to print out a piece of each array inside the loops?

Edit: Got it to print by making a void Print function, so we're done here. Thanks!
Last edited on
Topic archived. No new replies allowed.