What's wrong with my code?

#include <iostream>
#include <vector>

using namespace std;

bool LinearSearch( vector<int> data, int searchTerm )
{
int index, no, yes;
no = false;
yes = true;

for( index = 0; index < data.size(); index++ ) {
if( data[index] == searchTerm )
return true;
} // end for

return false;
}

int main()
{
vector<int> myvec = ( 1, 2, 3, 4 );

cout<<LinearSearch(myvec)<<endl;

system( "pause" );
return 0;

}
It doesn't compile.

 
vector<int> myvec = ( 1, 2, 3, 4 );


This is not how you initialize a vector to 4 elements. There is no easy way in this case without
doing 4 separate push_back()s.

and

 
cout<<LinearSearch(myvec)<<endl;


is attempting to call a function named LinearSearch with one parameter whereas
the function requires 2.

Topic archived. No new replies allowed.