need a help for hailstone sequence

how do I count the steps until the number gets to 1?

Last edited on
closed account (iGLbpfjN)
In the while loop use (n > 0 && n != 1);

In the cout of the if, just use n instead of n / 2

Inside the else, put n = 3 * n + 1; and use in the cout n instead of 3 * n + 1
Last edited on
Thank you so much, but how can I write the code to count the steps?
closed account (iGLbpfjN)
Just initialize an int with 0 as value, something like int count = 0;
Then, in the end of the while loop add a count++;
Last edited on
Topic archived. No new replies allowed.