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.

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
41
42
  
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] <<endl;
return 0;
}
int getData(ifstream& inFile, string element[MAX], double sc[MAX][7])
{
    ////////
}

int findElement(string element[MAX], double sc[MAX][7], int num, string skated)
{
     for(int i = 0; i < MAX; i++){
        for (int j = 0; j < 7; j++){
      return sc[i][j];
   }
}
}


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.
Registered users can post here. Sign in or register to post.