Fixing invalid input for square root by adding while/if block