title: Unordered Array Linear Search c++
body: <p>My assignment is to : Create a method to search an un-ordered array of integers for a value, 
  if the value is found return the index of its position in the array, if not found, return -1.</p>
  
  <p>It is only finding the number I enter if it is in Index 0, otherwise it is saying it is not found. I am not sure what went wrong, it was working when I had initialized my own array, but now it won't since I have the user create their own array.</p>
  
  <p>Any help would be great! thanks!</p>
  
  <p>So far my code is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  
  //SearchArray prototype
  int SearchArray( int arInt[], int elementAmount, int intSearched);
  
  
  int main()
  
  {
      int arInt[50];
      int elementAmount;
      int intSearched = 0;
      int i;
  
      cout &lt;&lt; "How many elements would you like to add to your array?\n";
      cin &gt;&gt; elementAmount;
  
      for( i = 0; i &lt; elementAmount; i++)
      {
          cout &lt;&lt; "Enter Number: ";
          cin &gt;&gt; arInt[i];
      }
  
          cout &lt;&lt; "Search array for integer:\n";
          cin &gt;&gt; intSearched;
  
          //Call search array method
          SearchArray(arInt, elementAmount, intSearched);
  
  
      system("pause");
      return 0;
  }
  
  
  int SearchArray( int arInt[], int elementAmount, int intSearched)
  {
          int i;
          bool foundInt = false;
  
          for (i=0; i &lt; elementAmount; i++)
          {
              if( arInt[i] == intSearched)
              {
                  foundInt = true;
                  cout &lt;&lt; "Integer was found in array at index " &lt;&lt; i &lt;&lt; endl;
              }
              else if (!foundInt)
              {
                  cout &lt;&lt; "Integer was not found in array\n";
  
                  system("pause");
                  return -1;
              }
  
  
          }
  
  }
  </code></pre>