index issue

This is the assignment. if anyone was confused. everything works except for the part in which it reads the first match and sends it back even if there are multiples of it
For this problem, please implement a linear search algorithm that performs this function. You
will be given two input files, “LSStandard.txt” and “LSTest.txt”. The LSStandard.txt
file contains integer values against which we are searching. (There will be no more than 100 of
these.) The LSTest.txt file contains a set of numbers that we are trying to locate within the
standard data set. (There will be no more than 50 of these.) Read both of these into separate
arrays and then determine which of the numbers in the LSTest file are included in the
LSStandard data set by using a Linear Search algorithm. Have your program print out a report
(to the console only is sufficient) that indicates whether the number was found or not.
Your output should look something like:
Number 1 ( 34) was located in position 15.
Number 2 ( 74) was not in the file.
Number 3 ( 56) was not in the file.
Number 4 (103) was located in position 75.
etc.
Your function header for the Linear Search function should look like:
int searchList(int stdList [], int numElems, int value)

this is everything after i saved both files in separate arrays. note that the code is a quick write up, ill change the variable names later. the same problem ive been having is that if it tries finding a number and its located in two different index position it always returns the first index position instead of both of them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for (int q=0; q=size2;q++)
{
  int rs=secfunc(array1;size1;array2[q])
  if(rs>=0)
  {
    cout<<rs << "\n";
  }
}

return 0;

int secfunc(int arr[],int SIZE, int values)
for (int a=0;a<SIZE;a++)
 {
  if(arr[a]==values)
  {
   return a;
  }
 }
return -1;
}

Last edited on
Topic archived. No new replies allowed.