Collatz Conjecture

I'm currently having some trouble making a C++ program for the collatz conjecture using a while loop nested inside of a for loop. After numerous rewrites, i've managed to get it to output the proper results, but only after one loop out of 10. I've tried going over it but I can't seem to see my problem; Do any of you have suggestions or ideas to what i've done wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdlib>
#include <iostream>
#include <fstream>             

using namespace std;

int number, result;                                //

int main()
{
    for(number = 1; number <= 10; number ++)
    {
        while(result != 1)
        {
            cout << number << endl;
            if(number % 2 == 0)
            {
                result = number /2;
                cout << result << endl;
            }
            else
            {
                result = 3 * number + 1;
                cout << result << endl;
            }
                number = result;
        }
    }
system("Pause");
return 0;
}
Topic archived. No new replies allowed.