Minor sequence error in C++ program output
<p>I am trying to output "states" for any binary number that is inserted (for each 0 it outputs a random number between 1 &amp; max), for example 10100 should output 2, random number between 1 &amp; 2, 3, random number between 1 &amp; 3, random number between 1 &amp; 3. Thus looking like 21323 or 223212 or 21313, etc. But the output my program is giving me is 23456 - why?</p>

<pre><code>int main()
{
    char binaryArray [0];
    int c1=1;
    int c0=0;
    int i=0;
    int n;

    cout &lt;&lt; "Enter length of binary: "; //Length = total number of 1s &amp; 0s
    cin &gt;&gt; n; 

    cout &lt;&lt; "Enter binary number: ";
    cin &gt;&gt; binaryArray;

    cout &lt;&lt; "States: ";

    for(i; i&lt;n; i++)
    {
        if(binaryArray[i]=1)
        {
            c1++;
            cout &lt;&lt; c1;
        }
        else if(binaryArray[i]=0)
        {
            c0++;
            cout &lt;&lt; rand()%c1+1;  
        }
        /* if(c0 &gt; c1)
        {
        cout &lt;&lt; "Invalid Binary Representation.\n" &lt;&lt; endl;
        exit(0); 
        } */
    }

    system("PAUSE");
    return 0;
}
</code></pre>
