this is a prog to search an array of random numbers. i'm trying to use recursion, but something is wrong with the function f_search. can anyone help? thanks again
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//functions
int f_search(int, int, int);
main()
{
int const array_size=400;
int array[array_size], holder, key;
//get key
cout<<"enter an int from 1 to "<<array_size*2<<endl;
cin>>key;
//seed
srand(time(0));
//load aray
for (int i=0; i<array_size; i++)
{ array[i]=1+rand() %array_size*2;
}
//sort array
for (int i=0; i<array_size; i++)
{ for (int x=0; x<array_size; x++)
{ if (array[x]<array[x-1] && x!=0)
{ holder=array[x];
array[x]=array[x-1];
array[x-1]=holder;
}}}
//display array
for (int i=0; i<array_size; i++)
{ cout<<array[i]<<" ";
}
//search
f_search(int array[], int array_size, int key);//error: expressino syntax
return(0);
}
int f_search(int a, int size, int key)
{
int location=4;//still working on, 4 is dummy value
if (size/2 == key)
{ cout<<"the number you picked ("<<key<<") was found in element "<<location;
return 1;
}
else
f_search(int a, int size/2, int key);//error: expressino syntax
}