C++: Programming Problem - Ulam Sequence

The Ulam Sequence

A mathematician named Ulam proposed generating a sequence of numbers from any positive integer n (n > 0) as follows: Here are some examples for the first few integers.
   2 ->  1
   3 -> 10 ->  5 -> 16 ->  8 ->  4 ->  2 ->  1
   4 ->  2 ->  1
   5 -> 16 ->  8 ->  4 ->  2 ->  1
   6 ->  3 -> etc as for 3 above.
   7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> see 5 above.

Write a program that shows the sequence

Write a program that reads a number (in a while loop of course) and prints the Ulam sequence for it.