Project Euler task #8, code starts returning wrong answers after certain point : <p>I am having some sort of a problem in a task from
 <a href="https://projecteuler.net/problem=8" rel="nofollow">https://projecteuler.net/problem=8</a>, (finding highest product of 13 consecutive numbers from a 1000-number string) where up to some point the program gives me predictable results and then the function returns a number very close to the <strong><em>unsigned long long int</em></strong> range. The point where it occurs depends on the values which were read, for instance if the string of numbers consisted mostly of 8s and 9s, it would happen sooner than it would if it had only 5s and 6s. Why does it happen?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;


int product (int res, int a, char buffer[]){
for (int i = 0; i &lt; a; i++){
//simple char to int conversion
res*=(buffer[i] - '0');
}

return res;
}

int main () {
char check;
int res = 1;
fstream plik;
plik.open ("8.txt");
unsigned long long int high;
unsigned long long int result;
//main function in the program
if (plik.good()){
    char buffer [13];
    for (int i = 0; i &lt; 13; i++){
        plik &gt;&gt; buffer[i];
    }
    result = product (res, 13, buffer);
    high = result;
    cout &lt;&lt; high &lt;&lt; endl;
    //the main checking loop
    while (!plik.eof()){
    //just an interruption to make it possible to view consecutive products
    //the iteration in the buffer
    for (int i = 0; i &lt; 12; i++){
    buffer[i] = buffer[i+1];
    }
    plik &gt;&gt; buffer[12];
    result = product (res, 13, buffer);
    //comparison between the current product and highest one
    if (high &lt; result){
    high = result;
    }
    cin &gt;&gt; check;
    cout &lt;&lt; high &lt;&lt; endl;
    //again a tool for checking where the problem arises
    for (int i = 0; i &lt; 13; i++){
        cout &lt;&lt; buffer[i] &lt;&lt; "  ";
    }
    cout &lt;&lt; endl;
    }
    plik.close();
    cout &lt;&lt; high &lt;&lt; endl;
}

return 0;

}
</code></pre>

<p>The program prints out the currently highest product and all the numbers currently contained in the array.
It looks like this:
<a href="http://i.stack.imgur.com/E9FaK.png" rel="nofollow">The error</a></p>
