Wondering if someone could point me in the right direction.
Below is some code which performs a simple calc on a number if it is greater the 1 and then stops and outputs the Count when the number finally reaches 1.
Now so far i've only able to make it so you input one Int and you then get the reuslt.
I would like to be able to input a number, have the code run through the numbers, output the count for that particular number, then Increase the original inputted by one and continue running, ad infinitum.
Any ideas what i should do?
rewrite the whole thing again using some For loop?, maybe these mystical array things, or am i just out of my depth
Code:#include <iostream> using namespace std; int main(int argc, char* argv[]) { int count = 1; int N; int X; cout<<"Input Number: "; cin>> N; cin.ignore(); X=N; while (X != 1) { if (X % 2 == 0) { X /= 2; } else { X = X * 3 + 1; } ++count; } cout << "cycle length of " << N << " is " << count << endl; cin.get(); return 0; }



LinkBack URL
About LinkBacks



