You keep “propagating” the same value over and over.
To achieve your goal, you need to save your result in "multiply", then * 2 of this variable. Something like that:
int multiply = number * 2;
while (true) {
cout << "Answer: " << multiply << endl;
multiply = multiply * 2;
}
EDIT: A more elegant way to do this is using recursive functions. You can find a useful example here .
Malva source
share