Im writing this converter and i dont see why the first time it gives me the right result

but after it gives me one 0 less every time.

EX. First time 8 --> 1000

After 8 --> 100

Code:#include <iostream> using namespace std; #include <cstring> #include <cstdlib> int number, total, binary[8]; void prog(); int main() { prog(); return 0; } void prog() { cout<<"Enter decimal to convert: "; cin>>number; while(number>0) { if((number%2)==0) { binary[total] = 0; number = number/2; total++; /* increasing by one each time will yield the number of numbers in the array. */ } else { binary[total] = 1; number = number/2; total++; } } total--; while(total>=0) { cout<<binary[total]; total--; } cout<<endl<<endl; prog(); }