Program will compile but crashes
Program compiles but crashes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<iostream>
int calculateFactors(int x)
{
int factorCount = 0;
while(true)
{
for(int j = 0; j <= 100; j++)
{
if(x % j == 0)
factorCount++;
}
break;
}
return factorCount;
}
int main()
{
std::cout << calculateFactors(10);
return 0;
}
|
That's a divide by zero error at line 10 when j == 0.
Thanks didn't catch that!
Topic archived. No new replies allowed.