Every programmer has, at some point, fallen into a logical trap. While building a simple console-based electrical circuit simulator in C++, I stumbled upon a classic boolean logic mistake that completely broke my code.

Here is how to build this useful engineering tool and, more importantly, how to avoid the infinite loop trap!

In physics, calculating the total resistance depends on how components are linked:

Series: R_total = R1 + R2 + ... + Rn

Parallel: R_total = (R1 * R2) / (R1 + R2)