C++ : integer constant is too large for its type

Posted by user38586 on Stack Overflow See other posts from Stack Overflow or by user38586
Published on 2013-10-31T20:13:29Z Indexed on 2013/10/31 21:55 UTC
Read the original article Hit count: 193

Filed under:
|

I need to bruteforce a year for an exercise. The compiler keep throwing this error:

bruteforceJS12.cpp:8:28: warning: integer constant is too large for its type [enabled by default]

My code is:

#include <iostream>

using namespace std;

int main(){

    unsigned long long year(0);
    unsigned long long result(318338237039211050000);
    unsigned long long pass(1337);

    while (pass != result)
    {
    for (unsigned long long i = 1; i<= year; i++)
        {

        pass += year * i * year;

        }

        cout << "pass not cracked with year = " << year << endl;
        ++year;

    }

        cout << "pass cracked with year = " << year << endl;
}

Note that I already tried with unsigned long long result(318338237039211050000ULL);

I'm using gcc version 4.8.1

EDIT:

Here is the corrected version using InfInt library http://code.google.com/p/infint/

#include <iostream>
#include "InfInt.h"

using namespace std;

int main(){

    InfInt year = "113";
    InfInt result = "318338237039211050000";
    InfInt pass= "1337";

    while (pass != result)
    {
    for (InfInt i = 1; i<= year; i++)
        {

        pass += year * i * year;

        }

        cout << "year = " << year << "  pass = " << pass <<  endl;
        ++year;

    }

        cout << "pass cracked with year = " << year << endl;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about gcc