Pretty sure the negative number issue means that you are passing the maximum integer - you need to use long or long long or add an error message once you pass the maximum integer.