Hailstone sequence

I cant figure out how to return the largest number in a hailstone sequence while using a loop and no recursion.

My sequence is {7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}

The answer my code is giving me is 22.

int largestNum(int n)
{
int t = 0;
int k = 0;
while(k != n)
{
k++;
t = max(next(n), length(n));
}
return t;
}
a loop is recursion.
I need to use a loop, any advice would be helpful.
The first advice is:
post a compilable code (with code tags, see http://www.cplusplus.com/articles/jEywvCM9/) to reproduce the problem.
After that, I'm sure you will get other advices.
Topic archived. No new replies allowed.