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++
// 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
}