Problem in balanced paranthesis

My code: https://ide.codingblocks.com/s/243582

It does not give correct value when i take input wrong values

How can i solve this?

@princeky4,
Corrected code here