can't find whats wrong with my program

so this is my program
if i insert 150 after i run im expecting to get this
1 0 0 1
but im getting 1 0 0 0
why ?

#include "stdafx.h"
#include "iostream"
using namespace std;
int main()
{
int a=128 ,b=64 ,c=32 ,d=16 ,e=8 ,f=4 ,g=2 ,h=1 ,x ,m ,l ,i ,k ,j;
cout << "type a number to convert from decimal to binary" ;
cin >> x;

if (x>=a)
{
cout <<" 1 " ;
l=x-a ;
}
else
{
cout << " 0" ;
x=l;
}

if (l>=b)
{
cout<<" 1" ;
i=l-b ;
}
else
{
cout << " 0" ;
l=i ;
}
if (i>=c)
{
cout<<" 1" ;
j=i-c ;
}
else
{
cout << " 0" ;
i=j ;
}
if (j>=d)
{
cout <<" 1" ;
k=j-d ;
}
else
{
cout << " 0" ;
j=k;
}

cout << " " << k << endl;
cin >> m ;
return 0;
system("pause");
}
The problem is here:
1
2
3
4
5
else
{
cout << " 0" ;
l=i ; //<-This line here
}

That line should be the other way around.
Topic archived. No new replies allowed.