title: Counting different elements in an array
body: <p>I got this really easy project however i got stuck in a simple issue.</p>
  
  <p>User enters a number not that is larger than 99 and smaller than 1 000 000.</p>
  
  <p>I am supposed to get the number of digits in that number and how many times each one occurs</p>
  
  <p>E.g: 112233 = 6 digits and 3 different numbers</p>
  
  <p>I was able to do the first part however my second part of part is not working.</p>
  
  <p>Here is the part not working:</p>
  
  <pre><code>int getDiff(int CLP, int Num)
  {
  
      int counter = 0, i = 0, j = 0;
  
      for (int x = CLP, i = 0; x &gt;= 1; x /= 10, i++) {
          PlateNumberArray[i] = x % 10;
  
          cout &lt;&lt; endl
               &lt;&lt; "Test===&gt;" &lt;&lt; PlateNumberArray[i] &lt;&lt; endl;
  
      } // end of "x = CLP" for loop
  
      while (i &lt; Num) {
          j = 0;
          while (j &lt;= Num) {
              if (PlateNumberArray[i] == PlateNumberArray[j])
                  NumberCounter[i]++;
              j++;
          } //end of while(j &lt;= i)
          i++;
      } //end of while(i &lt; Num)
  
      for (int i = 0; i &lt; Num; i++)
          counter += NumberCounter[i];
  
      return counter;
  }
  </code></pre>
  
  <p>if for example my input is 112233 the return value should be 3, however i am getting 12</p>
  
  <p>if input is 1122 the return value should be 2, however i am getting 8</p>
  
  <p>Here is the whole program i have written so far:</p>
  
  <pre><code>/*====================================================================================
  Headers and namespace
  ======================================================================================*/
  
  #include &lt;iostream&gt;
  
  using namespace std;
  
  /*====================================================================================
  Prototypes list
  ======================================================================================*/
  
  int getNum(int); //This function checks how many digits there are in a plate number
  int getDiff(int, int); //This function checks how many different numbers are there in the plate number
  
  /*====================================================================================
  Global variables list
  ======================================================================================*/
  
  int PlateNumberArray[6];
  int NumberCounter[6];
  
  /*====================================================================================
  main Function
  ======================================================================================*/
  int main()
  {
  
      //Declaring variables
  
      int CLP;
  
      //End of Vriables Declration
  
      cout &lt;&lt; endl
           &lt;&lt; "=============================" &lt;&lt; endl;
  
      cout &lt;&lt; "Enter your vehicle's plate number" &lt;&lt; endl;
  
      do {
          cin &gt;&gt; CLP;
  
          if (CLP &gt;= 1000000)
              cout &lt;&lt; "Plate number can be no longer than 6 digits, please re-enter" &lt;&lt; endl;
          else if (CLP &lt; 100 &amp;&amp; CLP &gt;= 0)
              cout &lt;&lt; "Plate number can not be less than 3 digits, please re-eneter" &lt;&lt; endl;
          else if (CLP &lt; 0)
              cout &lt;&lt; "Plate number can not be a negative, please re-eneter" &lt;&lt; endl;
  
      } while (CLP &gt;= 1000000 || CLP &lt; 100);
  
      int Num = getNum(CLP);
      cout &lt;&lt; getDiff(CLP, Num);
  
      return 0;
  }
  /*====================================================================================
  getNum Function
  ======================================================================================*/
  int getNum(int CLP)
  {
  
      //Declaring variables
  
      int Num;
  
      //End of Vriables Declration
  
      if (CLP &gt; 99999)
          Num = 6;
      else if (CLP &gt; 9999)
          Num = 5;
      else if (CLP &gt; 999)
          Num = 4;
      else if (CLP &gt; 99)
          Num = 3;
  
      return Num;
  }
  /*====================================================================================
  getDiff Function
  ======================================================================================*/
  int getDiff(int CLP, int Num)
  {
  
      int counter = 0, i = 0, j = 0;
  
      for (int x = CLP, i = 0; x &gt;= 1; x /= 10, i++) {
          PlateNumberArray[i] = x % 10;
  
          cout &lt;&lt; endl
               &lt;&lt; "Test===&gt;" &lt;&lt; PlateNumberArray[i] &lt;&lt; endl;
  
      } // end of "x = CLP" for loop
  
      while (i &lt; Num) {
          j = 0;
          while (j &lt;= Num) {
              if (PlateNumberArray[i] == PlateNumberArray[j])
                  NumberCounter[i]++;
              j++;
          } //end of while(j &lt;= i)
          i++;
      } //end of while(i &lt; Num)
  
      for (int i = 0; i &lt; Num; i++)
          counter += NumberCounter[i];
  
      return counter;
  }
  </code></pre>