So here I have a part of my code where I define macros to set the identifier MIN_BIT
to a value based on user input:
#define MIN_BITS(n) 1*n
int MIN_BIT = MIN_BITS(n);
And then I take user input for the value of 'n' in the main function.
Now, I have a function to take LSB, arrange it in an array, and print the array in reverse order so MSB is on the left:
void print_binary( unsigned number )
{
unsigned bits [ MIN_BIT ] ; // <-- error here
int count = 0 ;
while( number>0 || count < MIN_BIT )
{
bits [count] = number % 2;
number >>= 1;
count++;
}
for( int i = count -1; i >=0; i--)
cout << bits[i];
}
However, on the line marked 1 in the above code, I get an error "expression must have a constant value". The value of variable MIN_BIT cannot be used as a constant.
Please suggest a workaround for the issue, or a way to implement this differently.