Array searching i can not figure this out for the life of me

'''
const int rows = 3;
const int collums = 2;
int selectionArray[rows][collums] =
{
{1, 30},
{2, 100}
};
'''
this is the code for the array
'''
int arraySearch(){
Serial.println("");
Serial.println("What would you like to open boot = 1 or door = 2: ");
while (Serial.available()==0){}
bootOrDoor = Serial.parseInt();

for (int i=0; i<3; i++) {
if (bootOrDoor == (selectionArray[i][0])){
Serial.println("distance needed");
targetDistance = (selectionArray[i][i]);
Serial.println(targetDistance);

}

}
return targetDistance;
'''
this is the code for searching the array
the code works how i want for the door when i input the number 2 i get an output of 100
however when i input the number 1 i get an output of 1 and i am unsure how to fix this any help would be appreciated

I see an array 2x2 cells. Why you use cycle from 0 to 2 ?
Try to add more debug to serial: current values of each var on each iteration etc.

(selectionArray[i][i]);

It looks like a typo ... [i][1]

do you mean finding the value of bootOrDoor

thank you so much i love you been stuck on this for an hour and a bit over that, i havent been coding that long so thank you very much

i have another question could i use the same format for the user choosing between cm and inchs? thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.