title: C++ rand() not working with string array
body: <p>I'm creating a small program that allows the user to input 3 names (or whatever string they want). The program should then display all three strings (which is working), then it should use the <code>rand()</code> function to randomly display one of the three strings. This is the part that isn't functioning properly.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void display(string[], int);
  
  const int SIZE = 3;
  
  int main()
  {
      string names[SIZE];
  
      for (int i = 0; i &lt; SIZE; i++)
      {
          cout &lt;&lt; i + 1 &lt;&lt; ": ";
          getline(cin, names[i]);
      }
  
      cout &lt;&lt; endl;
      display(names, SIZE);
  
      int name = rand() % (2 + 1 - 0) + 0;
      cout &lt;&lt; names[name];
  
      cin.get();
  
      return 0;
  }
  
  void display(string nm[], int n)
  {
      int i = 0;
  
      for (i; i &lt; n; i++)
      {
          cout &lt;&lt; "Name " &lt;&lt; i + 1 &lt;&lt; ": ";
          cout &lt;&lt; nm[i] &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>I had it set up differently before, and it gave me an error, but after changing it to what it is now, it always gives me the last element [2].</p>
  
  <p>Is this a code error, or is it just that <code>rand()</code> always gives the same output on the same system?</p>