Project Euler with C++ - compiler won't process after 100 x 101
<p>I've started working with C++ and was fiddling around with some problems on projecteuler.net.</p>

<p>I'm on question #4 and here's my code:</p>

<p>algorithm to check whether the number is a palindrome:</p>

<pre><code>bool forwardCheck(long posPal){
long n = posPal;
long rev = 0;
long dig;

    while (posPal &gt; 0){
        dig = posPal % 10;
        rev = rev * 10 + dig;
        posPal = posPal % 10;
    }

    return n == rev;
}
</code></pre>

<p>main program:</p>

<pre><code>int main(){
long palindrome;

cout &lt;&lt; "We are finding the largest palindrome made from two 3-digit numbers.\n"
     &lt;&lt; "Calculating...\nCalculating...\nDone!\n";

for (long i = 100; i &lt; 1000; i++){
    for (long j = 100; j &lt; 1000; j++){
        long mult = i * j;
            if (forwardCheck(mult)){
                palindrome = mult;
                //testing function above
                cout &lt;&lt; mult &lt;&lt; " is a palindrome!\n";
            } else
                //testing function above
                cout &lt;&lt; mult &lt;&lt; " is not a palindrome...\n";
    }
}


cout &lt;&lt; "The largest palindrome composed of two 3 digit numbers is: " &lt;&lt; palindrome
     &lt;&lt; endl;

return 0;
}
</code></pre>

<p>I'm using X11 on OS X as my compiler with g++ and my problem is that, using the code above, the numbers get to 101,000 as the multiple and then stops and stalls after that.  My question is:</p>

<p>Why is it doing this?  Am I approaching this inefficiently?  </p>

<p>I realize that an alternative is to start from long = 999 and iterate downwards but I've coded but it gets stuck after the "Done!" statement (yes, I know it's a bit ambitious to program that in before the algorithm has run but I like to be optimistic. :)</p>

<p>By stuck and stalls, I mean that the CPU usage spikes but nothing is written to the console.  </p>

<p>As a general side note:</p>

<p>Is there a way I can debug through the console, i.e. have it tell me what it's doing similar to echo in windows command prompt?  I'm new to OS X too...</p>
