basic array problem--please help.

jamesfalter (7)
So, I'm pretty new to c++, and I'm having trouble with the following function. Its supposed to take an unsigned integer and convert it into it's binary representation. However, I am getting persistent runtime errors, and am at my wits end on how to fix it. can someone help me, or suggest a better way to do this? It would be very much appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void binaryOutput(unsigned int x){
  int count;
  int a=x;
  int b=x; 
 while(a<0){
   count++;
   a/=2;
}
 int array [count];
 for(int i=0; i<count; i++){
   if(b<0){
   array[i]=b%2;
   b/=2;}
 }
Last edited on
Registered users can post here. Sign in or register to post.