Hi i need help on searching an array for a match. They can be in any order, and does not need to be in a sequence. The theArray has 6 numbers in each row, with 10 lines (i have made 2 to keep things simple). The randArray has 8 numbers. I need to check these 8 numbers with the 6 numbers in each row of theArray, then increment the count if there are matches found on each line

#include <iostream>
using namespace std;
int main()
{
int theArray[1][2][12] = {{{1,1,1}}, {{1,1,2}}, {{1,1,3}}, {{1,1,4}}, {{1,1,5}}, {{1,1,6}},
			{{1,2,10}},{{1,2,11}},{{1,2,12}},{{1,2,13}},{{1,2,14}},{{1,2,15}}};
int randArray[1][8] = { 1 2 3 4 5 12 7 8 };
int count[10];
	for (int i = 0; i < 1; i++)

	{
		for (int j = 0; j < 10; j++)
		{
			for (int k = 0; k < 6; k++)
			{

				for (int check = 0; check < 8; check++)
				{
					for (int m = 0; m < 6; m++)
					{
						if (randArray[i][check] == theArray[i][j][m])
						{
							count[l] += 1;
						}
					}
				}
			}
		}
	}
 cout << count[0] << endl
		<< count[1];

	return 0;
}
//---------------------------------------------------------------------------

So it will display:
5 matches
2 matches

Edited 6 Years Ago by Vllinator: n/a

It always helps to be as clear as you can with the requirements of the task before trying to start. For example, the declaration of theArray and randArray seem a little weird. In particular I see no benefit to using a single index in an array. I would declare an array of 10 rows with 6 ints per row as:

int myArray[10][6];

If you must initialize the array on declaration then it would be something like

in myArray[10][6] = { {1, 3, 14, 3, 7, 8},
                      {9, 77, 43, -5, 4, 0},
                      //etc
                    }

Though I prefer to fill complex arrays using loops whenever possible.

Remember to put commas between the values in the initialization sequence.

This article has been dead for over six months. Start a new discussion instead.