1. Learn to use the Language:
As Aesclaell already stated, indentation means nothing to the compiler; use code blocks instead. As a rule of thumb, always use a code block after a control statement like
if
or
for
. It doesn't hurt and helps you prevent errors like these.
return
is most probably not what you intended to use here: I suspect all you wanted to do is exit the loop. The correct command for that is
break
:
for(int i=0; i<len;> {
if(mouse_dna[i] != unknown_dna[i])
{
mouseDistance++;
break;
}
}
2. Learn to use the compiler
In the standard setting, all compilers I know will issue warnings up to and including level 3. With that setting, the compiler should have warned you about unreachable code, referring to the issue discussed above. Learn to read and heed warnings - don't ignore them! Good programs will issue no warnings at all.
3. Learn to use the Debugger
Even ignoring the above two methods, you would have found the issue with the help of the debugger, and quite prossibly other issues on top of that
The Debugger is the best friend of a C/C++ developer: it will help you locate problems that can't be spotted by the compiler or prevented using proper syntax. it will even help you identify problems that are impossible to spot after looking at the code for a week, e. g. a file you try to open being access-protected, or an instable internet connection that intermittently fails to transport the data you're waiting for, or the mouse clicks you can't react to due to a defective USB connector or bad driver.