Rangek.runge4(count, y, dist);
What is it supposed to be doing, and what are the types and values of
y
and
dist
?
if((count%2) != 0)
{
fprintf(output, "%f\t%f\n", count, y[0]);
continue;
}
cout << "Counting: " << count << " seconds\n";
count % 2
will yield non-zero for odd numbers so that will be after 1 second, 3 seconds etc; so every two seconds.
The
fprintf()
statement uses the
%f
format control character to print a floating point value, but the variable
count
is a long integer. I don't know what
y[0]
might be.
The
continue
statement goes back to the top of the loop and gets the time again. This will (probably) be fairly close to the last iteration so it will call the
fprintf()
statement a second time within the current second.
You need to rethink your logic and figure out exactly what you are trying to do. It would be better to save the difference between your times in a second variable and wait till that changes before doing the print; something like:
timeDifference = 0;
lastDifference = 0;
while (true)
timeDifference = time2 - time1
if (timeDifference != lastDifference)
lastDifference = timeDifference
print details
end if
if (lastDifference > 10)
return
end while