Here is my code so far and I am stuck. The closest value to 7 in terms of absolute value is 5. How can I check each element of the array to see if it is the closest element and then return that value. I know this is probably easier than I think but I am a beginner at programming.
#include <iostream>
#include <cmath>
using namespace std;
const int MAX = 25;
int searchArray(int [], int); \\prototype
int main(){
int numArray[MAX] ={1,4,5,10,11,12,13,14,15,16,17,18,19,20,35,26,43,15,48,69,32,45,57,98,100};
searchArray(numArray, 7);
system("pause");
return 0;
}
int searchArray(int a[], int b){
int distance = 0;
for(int i=0;i<MAX;i++){
if(i==b)
return i;
else if(i<b || i > b)
abs(distance) == i-b;
return distance;
}
}