S
Smitsky
Why do I get (using Dev-C++) "111," when I should be getting "101" when I
enter "5?" I never get a "0" as an output. Can anyone let me know why?
Thanks. Steve
//----------------------------Code Starts------------------------------->
#include<stack>
#include<iostream>
using namespace std;
int main()
{
stack<int> s;
int number;
int digit;
cout<<"Please enter a decimal number to convert to binary.\n";
cin>>number;
while(number>0)
{
digit=number%2;
s.push(digit);
number=number/2;
}
while(!s.empty())
{
s.pop();
cout<<digit;
}
cout<<endl;
return 0;
}
//-----------------------------End Code---------------------------->
enter "5?" I never get a "0" as an output. Can anyone let me know why?
Thanks. Steve
//----------------------------Code Starts------------------------------->
#include<stack>
#include<iostream>
using namespace std;
int main()
{
stack<int> s;
int number;
int digit;
cout<<"Please enter a decimal number to convert to binary.\n";
cin>>number;
while(number>0)
{
digit=number%2;
s.push(digit);
number=number/2;
}
while(!s.empty())
{
s.pop();
cout<<digit;
}
cout<<endl;
return 0;
}
//-----------------------------End Code---------------------------->