Simulating a PLC ladder diagram on arduino

If you want this result value to persist after your calculation then it needs to be a static variable, or declared outside the function. All the variables declared inside the function are discarded once the function returns.

Again, though, this is a very contrived way to evaluate expressions in an Arduino and I do not think you will be doing your co-workers any favors if you encourage them to design their Arduino sketches as if they were PLC programs. Using 'C' and C++ code you have far more flexibility and can produce far simpler solutions than you would achieve with the PLC approach you're using. Better IMO to describe the behaviour you're trying to achieve and then write it directly in 'C'/C++.

There are hundreds of different programming languages and types of computer and controller and the value comes from knowing what they're capable of and how to use them most effectively - not how to make them all look and behave like the first thing you learned.