Beginner C++: Strange Behaviour
<p>thanks for taking the time to read this question! </p>

<p>The program is to find the smallest prime number after one billion. at the end of int main() i included a console input <code>cin&gt;&gt;x;</code>with the intention of preventing the command prompt from closing too quickly so i can see the result. however, i realised that i must first enter something before it shows me the result i want. </p>

<p>SO the question is: why is this so even though the console output  statement  <code>cout&lt;&lt;i;</code>is before the input statement <code>cin&gt;&gt;x;</code>?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;math.h&gt;
using namespace std;

int is_prime(int x);

int main()
{
    for (int i=100000000;;i++){ 
        if(is_prime(i)){ 
                cout&lt;&lt;i;
                break;}
    int x;
    cin&gt;&gt;x;

       }

}

int is_prime(int x)
{
    double maxvalue = sqrt(static_cast&lt;double&gt;(x));
    for ( int i=2;i&lt;=maxvalue;i++){
        if (x%i == 0 ) return false; }
        return true;
}
</code></pre>
