Logic error

A logic error produces unintended or undesired output or other behaviour, although it may not immediately be recognized as such.

Often the only clue to the existence of logic errors is the production of wrong solutions, though static analysis may sometimes spot them.

Although this will not work in all cases, for example when calling the wrong subroutine, it is the easiest way to find the problem if the program uses the incorrect results of a bad mathematical calculation.

This example function in C to calculate the average of two numbers contains a logic error.

It is missing parentheses in the calculation, so it compiles and runs but does not give the expected answer due to operator precedence (division is evaluated before addition).