### finding element in 2D array

Hi, I need some help with two dimensional arrays. I need to write a function that will find the element in data, like user enters name and number of colon and it should output the element in that position. Here is the code I have but I'm stuck with 2D array function.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` `````` int main() { string element[MAX]; string skated; double sc[MAX][7]; int num; int goe; int row; ifstream inFile; inFile.open("scaleOfValues.txt"); //Tests if file exists if (inFile.fail()) { ..... } //Input data from file num = getData(inFile, element, sc); cout << "Enter element: " << endl; cin >> skated; cout << "Enter GOE: " << endl; cin >> goe; //Find element row = findElement(element, sc, num, skated); cout << "Points on this element\n" << sc[row][goe] <

Thank you for any suggestions
I presume that row k of the matrix (sc[k]) corresponds to the element k in the names (element[k]) and that names have 'num' elements and matrix has 'num' rows.

You seem to be interested in row k of the matrix, so you should find the position of the name that equals to 'skated'.

Obviously, that has nothing to do with the 'sc'. You are looking from the 'element' only.

You don't want to go through all MAX elements, because only 'num' are real. If 'skated' equals `element[i]`, then return i.
If none of the num elements matches, returns something that will reveal the caller that 'skated' was not found.

You should test the 'goe' too; that it is in valid range.
Topic archived. No new replies allowed.