title: identifier 'n' is undefined
body: <p>This is my <strong>code</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
  int array[100], beg, mid, end, i, num;
  
  cout &lt;&lt; "Enter the value of an array" &lt;&lt; endl;
  cin &gt;&gt; n;
  
  cout &lt;&lt; "Enter the values in sorted order (asc or desc)" &lt;&lt; endl;
  
  for (i = 0; i &lt; n; i++)
  {
      cin &gt;&gt; array[i];
  
  }
  
  beg = 0;
  end = n - 1;
  cout &lt;&lt; "Enter the value to searched in an array" &lt;&lt; endl;
  cin &gt;&gt; num;
  
  while (beg &lt;= end)
  {
      mid = (beg + end) / 2;
      if (array[mid] == num)
      {
          cout &lt;&lt; "Item found at this position" &lt;&lt; (mid + 1);
          exit(0);
      }
      else if (num &gt; array[mid])
      {
          beg = mid + 1;
  
      }
      else if (num &lt; array[mid])
          end = mid - 1;
  }
  cout &lt;&lt; "Number not found." &lt;&lt; endl;
  
   return 0;
  }
  </code></pre>
  
  <p>I am not able to find that what is my <strong>error</strong>. 
  It is always displaying </p>
  
  <blockquote>
    <p>identifier 'n' is undefined
    'n': undeclared identifier</p>
  </blockquote>
  
  <p>Please any one give the suggestion to me. Thanks in advance.</p>