code for two motors

It may be correct for two sketches (apart from the multiply-defined "transistorpin"), but not for one.

The compiler will have told you that.
You can have one "loop" and one "setup" in a sketch.

Please use tags when posting code