My if and else if are running at the same time : <p>I've got a program measuring distance from a rocket to the moon, so when the distance is >250, only the if runs. However when the else runs and the distance &lt;=250, the if continues to run while the else runs. If anyone can help me fix it I would be very thankful. </p>

<pre><code>do
{
if (distance &gt;250)
    {
        time += 1;
        y_pos = initial_y_pos - (vel_y * time)/2;
        x_pos = initial_x_pos + (vel_x * time)/2;
        //Sets the new x and y position when time is flowing so the rocket can move
        GFX_DrawLineTo(x_pos, y_pos, 3);
        GFX_UpdateDisplay();
        distance = sqrt(pow((y_pos-(y+312)),2)+(pow((x_pos-(x+440)),2)));
        mars_dist = sqrt(pow((y_pos-150),2)+pow((x_pos-1150),2));
        //distance calculation from the rocket to the moon. Needed for sphere of influence
        printf("%f\n",distance);
    }

else if (distance &lt;=250)
    {
        y_pos = initial_y_pos - ((vel_y * time) - ((gravity * time)/2));
        x_pos = initial_x_pos + ((vel_x * time) - ((gravity * time)/2));
        GFX_DrawLineTo(x_pos, y_pos, 3);
        GFX_UpdateDisplay();
        distance = sqrt(pow((y_pos-(y+312)),2)+(pow((x_pos-(x+440)),2)));
        mars_dist = sqrt(pow((y_pos-150),2)+pow((x_pos-1150),2));
        //printf("%f\n",distance);
        printf("%f\n", x_pos);
    }


    if (distance &lt;= 50)
    //If the rocket either hits moon or mars, this is responsible for recognising that
    {
        printf("Unlucky! Your rocket crashed into the moon!");
        return 0;
    }

}
//while (distance &gt; 250);
while ((0 &lt;= x_pos &amp;&amp; x_pos &lt;= 1280) || (0 &lt;= y_pos &amp;&amp; y_pos &lt;= 1024));
</code></pre>
