#include "library.h" int collatz(const int start) { int count = 0; int val = start; while (val != 1) // another test for is it odd is: if (val & 1) { if (val % 2 == 0) val = val / 2; else val = val * 3 + 1; count = count + 1; cout << count << ": " << val << "\n"; } return count; } void main() { while (true) { cout << "starting value? "; cin >> n; const int k = collatz(n); cout << "length of sequence starting from " << n << " is " << k << "\n"; } }