Array problem in C++

#include <iostream.h>
using namespace std;

void binary(int number);

int main() {
int b;

for (int x = 0; x < 256; ++x) {
binary(x);
if (x < 128)
cout << " " << x << " " << x <<endl;
else cout << " " << x << " " << 127 - x <<endl;
}
cin >> b;
return 0;
}

void binary(int number) {
int bitTable [8], y;
for (y = 0; number != 0; y++) {
bitTable[y] = number%2;
number /= 2;
}

while(y < 8) {
bitTable[y] = 0;
y++;
}


for (int j = y - 1; j >= 0; j--) {
int bit = bitTable[j];
cout << bit;
}

}

The above code is using an array to store bits as they are converted from decimal numbers.. But something is wrong.

The first number displayed is always some huge number. So for 255 decimal I should be getting 11111111, instead I get something like 378796481111111. I have tried setting the last element to 0(since they're being printed out in reverse), or not display it at all.. But then the one before this becomes a huge number instead, and it just removes one of the bits instead. Nothing seems to be working to fix it. Please help! (I am using Bloodshed Dev-cpp 4.9.9.2, assuming that information is important)

EDIT: Added the code tags I forgot.
[1627 byte] By [Garan] at [2007-11-20 11:22:59]
# 1 Re: Array problem in C++
Did you use your debugger to help find the problem?

I know that Dev-C++ comes with one, and this is a good time for you to get familiar with how to step through a program with the debugger and see what the values are at each step.

Regards,

Paul McKenzie
Paul McKenzie at 2007-11-9 1:25:35 >
# 2 Re: Array problem in C++
#include <iostream.h>
Wrong header. The correct header is <iostream>, not <iostream.h>.

#include <iostream>

Regards,

Paul McKenzie
Paul McKenzie at 2007-11-9 1:26:35 >
# 3 Re: Array problem in C++
I forgot to re-change the header after testing the program in another compiler just to see if that was infact the problem.. It was an older compiler requiring the .h extension.

And I figured out the problem now. Thank you for your help and replies!
Garan at 2007-11-9 1:27:36 >