You coded very wrong "if .... if else if ..." the bold if is wrong and must be discarded


if (side==1)
...
else if (side==2)
...