EOF error problem while taking input

You can see this Actual Solution to understand much better about the problem and why my solution worked, though when i used it, it was just a hunch.