question about loops

I have an assignment that I need to take a number divide it by 2 till it reaches 0, but the assignment wants me to state how many times the number was divided till it reached zero. Any help?
Also how would I get it to the loop the new product of the division to divide again and again?
Last edited on
First check for an even number. (Hint: modulus operator)
Run the number through a for loop

1
2
3
4
for(/*number*/; number > 0; count++)
{
    number /= 2;
}

Display the count

btw: A number divided by 2 will never equal zero unless it is zero itself. It will if integer division is used though.
what does the /*number*/ mean?
he means the number that the variable you are using is initialized to. e.g

for(int i=10; i>0; count++)

or just 'i' if the variable has already been declared
Topic archived. No new replies allowed.