c++ if statement will not end
<p>I am fairly new to c++ and am not sure if i am explaining this correctly.</p>

<p>I have a piece of code( a function) that does not end when running the whole program.</p>

<p>The purpose of the function is to first generate a random number from 0 to 1. Next if that random number is greater than 0.6, it goes into another function. That function virus_death works perfectly. If the random number is less than 0.6 then it will make the virus point push back into a vector called reached. It will also write the point to a file. However, the statment never stops.</p>

<pre><code>void replication(vector&lt;Virus&gt;&amp; virus, int a, int b, double&amp; times, int&amp; iv, 
                 ofstream&amp; data_file, int p, vector&lt;Direction&gt;&amp; direction_v, 
                 vector&lt;Virus&gt;&amp;replicate, int step)
{
    point R,P;

    double replicates  = ((double) rand() / (RAND_MAX));
    //how long the virus takes to reach the necleus

    if( replicates&gt;0.6)
    {
        cout&lt;&lt;"No Replication "&lt;&lt;endl;
        virus_death(times, iv, virus,a,b,data_file,p,direction_v, step);
    }
    else if( replicates&lt;=0.6)
    {
        cout&lt;&lt;"Replication"&lt;&lt;endl;

        ofstream tom;
        tom.open("Timing_nuc.dat");

        cout&lt;&lt;"Points"&lt;&lt;endl;
        R.x = virus[p].getx();
        R.y = virus[p].gety();
        R.t = virus[p].gett();

        cout&lt;&lt;"Write to File"&lt;&lt;endl;
        tom&lt;&lt;p+1&lt;&lt;"\t"&lt;&lt;R.x&lt;&lt;"\t"&lt;&lt;R.y&lt;&lt;"\t"&lt;&lt;R.t&lt;&lt;"\n";

        cout&lt;&lt;"New Points"&lt;&lt;endl;
        P.x = a;
        P.y = b;
        P.t = 0;
        cout&lt;&lt;P.x&lt;&lt;"\t"&lt;&lt;P.y&lt;&lt;"\t"&lt;&lt;P.t&lt;&lt;"\n";


        replicate.push_back(P);
        int aspa = replicate.size();
        cout&lt;&lt;"Replication Size:"&lt;&lt;aspa&lt;&lt;endl;
    }           
}
</code></pre>

<p>can someone please help me determine why once the point is pushed into the vector, it will not leave the function.</p>

<p>the code that calls this function is:</p>

<pre><code>void location_of_virus(vector&lt;Virus&gt;&amp;virus,double&amp; times, int&amp; iv,
                        ofstream&amp; data_file, vector&lt;Direction&gt;&amp; direction_v,
                        vector&lt;Virus&gt;&amp;virus_engulf, circle&amp;cell_c, 
                        circle&amp;nuclei_c, vector&lt;Virus&gt;&amp;replicate, int step)
{
    int a;
    int b;

    //int nc,cc,cmc,nci;
    float dis_c, dis_n;

    int virus_size= virus.size();
    //type = "virus";
    for(int i =0; i&lt;virus_size; i++)
    {
        a = virus[i].getx();
        b = virus[i].gety();

        //to check where the virus is in location to the environment
        dis_c = cell_c.distance(a,b);
        dis_n = nuclei_c.distance(a,b);

        if(dis_n &lt; 5)
        {
            location =" Inside Nucleus";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";
            replication(virus,a,b,times,iv,data_file,i,direction_v,replicate,step);
        }   
        else if(dis_n ==5)
        {
            location = "Nucleus";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";
            nucleus(virus,a,b,times,iv,data_file,i,direction_v,step);

        }
        else if(dis_c &lt;25 &amp;&amp; dis_n&gt;5)
        {
            location = "Cytoplasm";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";
            cytoplasm(virus,a,b,times,iv,data_file,p,direction_v,step);
        }
        else if(dis_c ==25)
        {
            location = "Cell Membrane";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";
            endocytosis(virus,a,b,times,iv, data_file,i,direction_v,virus_engulf,cell_c,nuclei_c);
        }
        else if (((a ==0 || a == 50 || a&gt;0 || a&lt;50)&amp;&amp; (b ==0 || b == 50 || b&gt;0 || b&lt;50)) &amp;&amp; dis_c&gt;15)
        {
            location ="Extracellular Matrix";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;direction_v[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";
        }
        else
        {
            location ="Left the System";
            cout&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;endl;
            data_file&lt;&lt;i+1&lt;&lt;"\t"&lt;&lt;virus[i]&lt;&lt;"\t"&lt;&lt;location&lt;&lt;"\n";

        }
    }
}
</code></pre>
