0
I was wondering is the display function wrong when I call the search function?
When it get the answer for the question in search function my compiler still print out both of the function i don’t know why int search(string arr[ROW][COLUMN], string STR) { for (int i=0; i<ROW; i++) { if (arr[i][0]==STR) { cout <<"Answer for the question: " <<arr[i][1] << endl; return i; } } return -1; } void display (string STR) { string arr[ROW][COLUMN]; int match= search(arr, STR); if (match == -1) { cout << "Please enter a choice from below\n"; //code for choice } }
5 ответов
+ 1
You declared arr[][] as int array and function defination has string arr[][], it should display error..
And what are the values to array, not mentioned there, how you storing..
And your while loop is infinite loop, no exit condition. Instead use
if(match== -1){
..
}
+ 1
Assign the values to string array arr. Then call search function. Otherwise it is empty array and return -1 only...
Edit :
Skylar Yang that row and column index values..
What and where is the values for
arr[0][0],arr[0][1],
arr[1][0],arr[1][1],
.......
.......
arr[99][0],arr[99][1]
0
You didn't initialize the arr in display() with size.
0
oops sorry i write the wrong code I updated the code again
0
I use const int ROW=100 and const int COLUMN =2 in declaration Jayakrishna🇮🇳
arr[0][0] to arr[99][0] will be the input file for question
arr[0][1] to arr[99][1] will be the input file for answer