leanear search not coming up with more than 1

I am having problem with my program, This is the first time i have tryed to post a program, so if i am doing somthing wrong just say,

The problem i have is when i go through the search i am supposed to find how often the number appears in the list. But when i do so, the the int search only comes up with one and does not show the that multiple appeard.

What would i need to add to have the search keep adding

thanks,
tman
********************************************************************************




int numberforarray (int amount, double number[]);
int LinearSearch (double number [], int size, double key);

int main ()
{

double number[20];
int amount;
double key;
int search;


amount = numberforarray(20, number);

cout<<"What number would you like to try and find?"<<endl;
cin>>key;
search = LinearSearch (number, amount, key);
if (search == -1)
{
cout<<"There were "<<amount<<" numbers entered in the array."<<endl;
cout<<"The number "<<key<<" was not found in the array!"<<endl;
}
else
{
cout<<"There were "<<amount<<" numbers entered in the array."<<endl;
cout<<"The number "<<key<<" was found at position "<<search<<"."<<endl;
}

}
/*
function
*/

int numberforarray (int amount, double number[])
{
char answer;
int index;
index = 0;
do
{
cout<<"Please enter a number for the array."<<endl;
cin>>number[index];
index++;
cout<<"Do you want to enter another number (y/n)?"<<endl;
cin>>answer;
} while (answer == 'y'|| answer == 'Y' && index<amount);
return index;
}

int LinearSearch (double number [], int amount, double key)
{
int j=0;
int position = -1;
bool found = false;

for (int j=0; j<amount;)
{
if( number[j]== key)
{
found = true;
position = j;


}
j++;
}
return position;

}
Topic archived. No new replies allowed.