454,446 Members | 1,317 Online Need help? Post your question and get tips & solutions from a community of 454,446 IT Pros & Developers. It's quick & easy.

# Looping with 2 dimensional arrays

 P: 35 hi, i need a program that takes an array of 6 numbers and compares these numbers to a two dimensional array of n columns (user decides a number between 1 and 18) and 6 rows. So i need to check if each of the rows in the 2 dimensional array have matching numbers to the original array.... Hope that makes sense. So far I have a function that kind of does this but it wont switch to the next row without including the first one so each result includes the result of all the rows before it. So I get.. 6 12 18 as a result instead of... 6 6 6 Here's my function.... Expand|Select|Wrap|Line Numbers void results (int draw[], int entry[][maxsize2], int size) {     int matches = 0;     for (int h=0; h
4 Replies

 100+ P: 147 hi, i need a program that takes an array of 6 numbers and compares these numbers to a two dimensional array of n columns (user decides a number between 1 and 18) and 6 rows. So i need to check if each of the rows in the 2 dimensional array have matching numbers to the original array.... Hope that makes sense. So far I have a function that kind of does this but it wont switch to the next row without including the first one so each result includes the result of all the rows before it. So I get.. 6 12 18 as a result instead of... 6 6 6 Here's my function.... Expand|Select|Wrap|Line Numbers void results (int draw[], int entry[][maxsize2], int size) {     int matches = 0;     for (int h=0; h

 P: 35 Thanks, that makes sense but for some reason it works if all the numbers in all the rows are equal (e.g. 1 2 3 4 5 6 in all of them) but otherwise it just gives me 1 as the answer for all the rows. MAXSIZE2 is the number of column which is determined by the user so I wasn't sure how else to include it in the function. May 30 '07 #3

 100+ P: 147 Thanks, that makes sense but for some reason it works if all the numbers in all the rows are equal (e.g. 1 2 3 4 5 6 in all of them) but otherwise it just gives me 1 as the answer for all the rows. MAXSIZE2 is the number of column which is determined by the user so I wasn't sure how else to include it in the function. Okay, but are you sure that you always want to compare against the maxsize2th element, as below? Expand|Select|Wrap|Line Numbers #         for (int j=0; j

 P: 35 Or do you really mean to compare against all of entry[j] through entry[j][maxsize2 - 1]? Oh ok i see how that is wrong now and yes i want to do what you have suggested above but i'm just not sure how to put that in a statement compring the two values. I get the impression that the nesting of your loops is a little different than what you want it to be. But you haven't explained what is contained in the rows and columns of entry[][], or the purpose of the size parameter, so I'm stil not sure what you're trying to accomplish in your function. I'm comapring lotto numbers so the first array is the winning numbers and the 2 dimensional one is entries of the user. So they have 6 numbers in each entry which is the row and up to 18 entries which is the number of colums. But I have to make it so the user inputs the amount of columns which is the second part of the array. So its actually entry[what user enters] MAXSIZE2 is up to 18 and size is what they actually enter May 30 '07 #5 