How do I tackle the no solution situation?

I am supposed to print 0, in case there’s no solution but i am not able to do it.

You can refer to this: