Can anyone help me with this problem?

“”"
#include
#include
using namespace std;

void isPrime(int TheNum,bool isprime){
for (int theDivison = 2; theDivison <= TheNum/2; theDivison++){
if (TheNum% theDivison == 0){
isprime = false;
break;
}
}
}

int main(){
int n = 3;
int TheSum = 2;
bool CouldDivide = true;
while (n <= 2000000){
isPrime(n,CouldDivide);
if (CouldDivide == true){
TheSum += n;
}
n = n+2;
}
cout <<TheSum;
return 0;
}
“”"

My code above got the output which is a negative integer. Can anyone explain it for me?

You are encountering an integer overflow. You will want to use a long long instead of an int.

Also, I’d recommend looking at the Sieve of Eratosthenes.

thank you, i will take a look.