HELP!! How to do exponents with while loop?

I have a problem that I'm stuck on, it requires to do exponents with JUST, and SOLELY while loop.

Let's put an example:
user input : 5
5
16
8
4
2
1
The sequence has length 6,
The largest x value so that 2^x <= 6 is [2].


The problem above have 3 loops, I got the first two correct, but I'm stuck on this last loop where you have to do exponents just by "while" loop. Pls help I know this is fundamental, but I'm a total beginner at C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// first of all, you need integer data types to store your data
int user, i = 1, values = 1;

cout << "input number : "; // explain user to input a number from keyboard
cin >> user; // get user input

    while(i < user) // loop until "i" value equals to "values"
    {
     values *= 2; // multiply values by 2, [values = values * 2]
     i++; // add i by 1
    }
    cout << user << endl; // display the user input
    
    i = 0;
    
    while(i < user)
    {
     cout << values << endl; // display the values
     i++, values /= 2; // divide values by 2
    }
ty so muchh
thumbs up!
Topic archived. No new replies allowed.