
Collatz conjecture
ok, so I am building a program that calculates a number that user enter, with the collatz conjecture principles.
A random number is entered, if it is an even number it shall be divided by 2,if it is an odd number it must be multiplied by 3 + 1 and then divided by 2.. This goes in a loop until the number is 1. I have already found the method for this, but I do not get the number to not be negative.
question is: how do I prevent the number from going over to the negative side?
First i tried : while(X>1) but that doesent work, so I thought while(X!=1) but that doesent work either. And when i enter the number 837799 the computer goes in to a endless loop..
I DONT WANT THE COMPLETE ANSWER, just a nod in the right direction!