recently I took it upon myself to start working on the Project Euler challenges. I am on problem seven, and have encountered a strange error in my code. In my code, I have a variable called, count
that counts the number of prime numbers found, but when I try to print it, it prints out as null.
#include <iostream>
int main()
{
bool isPrime = true;
for(int i = 1; i <= 10000000000;)
{
int count;
for(int factor = 1; factor = i; factor++)
{
if(i%factor == 0)
{
isPrime = false;
break;
}
}
if(isPrime) {count = count + 1;}
std::cout << count + "-";
if(count == 10001)
{
std::cout << count;
std::cout << i + "Final \n";
break;
}
i++;
}
}
When the line std::cout << count + "-";
runs, the output is:
--------------------------------------------------------------------------------------------------------
etc. I think it has something to do with the initialization of counts
, but I'm not sure. Thanks for any help!