title: Distinct numbers in c++
body: <p>I want to start by saying I am new to programming. I have a problem with writing a list of distinct numbers from another list in c++. Let's say I have a list <code>l1 = {1, 12, 2, 4, 1, 3, 2}</code> and I want to create a new list that looks like this <code>l2 = {1, 12, 2, 4, 3}</code>...</p>
  
  <p>This is what I wrote:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main() {
      int l1[100], l2[100], length, length1 = 0, i, j, a = 0;
      cin &gt;&gt; length; //set the length
      for (i = 0; i &lt; length; i++) {
          cin &gt;&gt; l1[i]; //add numbers to the list
      }
      l2[0] = l1[0]; //added the first number manually
      for (i = 0; i &lt; length; i++) {
          length1++;
          a = 0;
          for (j = 0; j &lt; length1; j++) {
              if (l1[i] != l2[j]) //this checks numbers in the second list
                  a = 1;         // and if they aren't found a gets the value  
          }                     //1 so after it's done checking if a is 1 it 
          if (a == 1)          //will add the number to the list, but if the  
              l2[j] = l1[i];  //number is found then a is 0 and nothing happens,
      } //                                         SUPPOSEDLY
      for (j = 0; j &lt; length1; j++) {
          cout &lt;&lt; l2[j] &lt;&lt; " ";
      }
  }
  </code></pre>
  
  <p>The output of this is <code>1 -858993460 12 2 4 1 3</code> so obviously I did something very wrong. I'd welcome any suggestion you might have, I don't necessarily need a solution to this, I just want to get unstuck. 
  Thanks a lot for taking time to reply to this.</p>