To clarify @Aki Suihkonen's comment, when performing:
outer % inner
If inner
is zero, you will get a divide by zero error.
This can be traced backward by calling isAFactor(0, 1)
.
It is in your for
loop in main
.
The first parameter to isAFactor(countOut, countIn)
is assigned in the outermost for
loop:
for (countOut = 0; ...
Notice the value you are initializing countOut
with.
Edit 1:
Change your `isAFactor` function to:
if (inner == 0)
{
cerr << "Divide by zero.\n";
cerr.flush();
return 0;
}
if (outer % inner ...
Place a breakpoint at either cerr
line above.
When the execution stops there, look at the Stack Trace. A good debugger will also allow you to examine the parameter / values at each point in the trace.