Prevent duplicate entry into vector? C++ : <p>I have a program that prompts a user to enter a value. Each value that the user enters gets placed into a vector 'other' which is there only for validation. If a duplicate value has been entered, the user will get a prompt until they enter a unique value.  </p>

<p>The main problem I am facing is that for some reason when running the code and printing out the results of the vector, there appears to be a duplicate entry. Could anyone please tell me why that is? </p>

<p>See below for my code:</p>

<pre><code>// prompt to continue
cout &lt;&lt; "Would you like to continue? [Y]es, [N]o: ";
cin &gt;&gt; toContinue;

while (toContinue == 'Y')
{
    bool isDuplicate = 0;

    // prompt for product no.
    cout &lt;&lt; "Please enter product number: ";
    cin &gt;&gt; productB; 

    // Validation check for duplicate entries
    for (size_t i = 0; i &lt; other.size(); i++)
    {
        if (productB == other[i])
            isDuplicate = 1;

        while (isDuplicate == 1)
        {
            cout &lt;&lt; "You have already entered this product number!" &lt;&lt; endl;
            cout &lt;&lt; "Please enter correct product number: ";
            cin &gt;&gt; productB;

            if (productB != other[i])
                other.push_back(productB);

            isDuplicate = 0;
        }
    }
    // prompt to continue
    cout &lt;&lt; "Would you like to continue? [Y]es, [N]o: ";
    cin &gt;&gt; toContinue;
}
</code></pre>
