Why doesn't this execute?

Another little problem while using my bigint class...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int main()
{
    for(int i = 3; lastPrime < 100; i+=2)
    {
        if(isPrime(i) && i < 100){
            lastPrime = i;
            string temp;

            stringstream strm;
            strm << i;
            strm >> temp;
            strm.clear();


            bigint t(temp);
            cout<<"\n";
            cout<<"\n";
            cout<<temp;
            total += t;
            }
    }

    total.print();
    cout<<"hello";

    return 0;

}


the loop executes perfectly, but nor the print function nor the hello execute...
Question: Why do you do this:
 
 for(int i = 3; lastPrime < 100; i+=2

This does almost the same thing as
 
 for(int i = 3; i < 100; i+=2


Unless you WANT the first prime number after 100 to be in the loop, it makes no sense. I'll take that back if that's what you wanted to achieve.

Otherwise, I'd seek the fault in your isPrime function. It might always return false. Also, I hope you defined total and lastPrime(especially lastPrime. There's a high chance that lastPrime is larger than 100 if you declared it without defining it).
Last edited on
Topic archived. No new replies allowed.