Alright, just like the title says I am trying to find the index of an array's value that is before and after a users chosen value. I know this sounds confusing..so let me break it down.
Let's say I have an array {1,3,5,9,13}
The user inputs 6 as their value.
I am trying to figure out how to find the index of 5 and 9, which are the values directly below and above 6. I know from looking at this array that the indexes are 2 and 3, but I can't figure out how to code something like this. Any ideas?
Here you go. It's not like I haven't done anything!! The bolded area is where I am tied up at. I want to find the index of the values directly below and after the "angle" which is the user input.
if(angle >= left[0] && angle <= left[lpos-1]){
for(int i=0; i < lpos; i++){
if(angle == left[i]){ // Checking to see if value user entered is in data set
cout << "Coefficient of lift is " << right[i] << endl;
equals = true;
}
elseif(i == (lpos-1) && equals == false){
if(left[i] < angle){
lowerAngle = i;
}
if(left[i] > angle && (lowerAngle + 1) == i){
higherAngle = i;
}
}
// Calculating Coefficient if not a value in data set
coeff = left[higherAngle] + left[lowerAngle];
cout << "Coefficient of lift is " << coeff << endl;
}
}else{
cout << "The angle you entered is not within the bounds of the data set." << endl;
}