Need a project done?

C++ Programming Developer

Search This Blog

Generic Decimal to Binary Converter in C++

#include <iostream>
#include <iomanip>
void binary_converter (int);
using namespace std;

int main()
{
float Num;
cout<<"Number: ";
cin>>Num;

cout<<"Binary: "; binary_converter(Num);
cout<<endl;
return 0;
}

void binary_converter (int Num)
{
int a, i = 20;
while (Num != 0)
{
a = Num % 2;
Num=Num/2;
cout<<"\r"<<setw(i--)<<a;
}

}
"Don't let anyone ever make you feel like you don't deserve what you want."