I did this for the Euler project problem 5, but for some reason I get a floating point exception:
#include <iostream>
using namespace std;
int main ()
{
long num;
bool isnum = false;
long i = 20;
while (isnum == false)
{
for (int j = 0; j <= 20; j++)
{
if (i % j != 0)
{
break;
}
else
{
num = i;
isnum = true;
}
}
i+=20;
}
cout << num << endl;
return 0;
}
What I don’t understand is how there can be a floating point exception when I do nothing with my code that would output a non-integer number.
There’s a division by zero here because j is initialized to 0.