I'm taking an intro programming course, but I'm having difficulty with my current assignment.
Here's the assignment:
Using while statement, write C++ code to display all the bit values up to the number entered by a user through pow(base, n) function.
Output Example:
Enter a bit number : 8
1 bit: 2
2 bit: 4
3 bit: 8
4 bit: 16
5 bit: 32
6 bit: 64
7 bit: 128
8 bit: 256
Here's what I have so far. Not much, I know:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
int bitNum, base, n;
base = ;
n = ;
while (condition)
{
statements
}
cout << "Enter a bit number: " << bitNum << endl;
return 0;
}
I sort of understand loops, but I'm not sure what while condition I should use and how to implement the pow() function. Could someone help point me in the right direction. I'm not looking for my homework to be done for me, but just to get an idea of what to do.