I wrote a
program that outputs the binary number of a decimal number passed to it, however the binary number out putted has an extra 0 in the 10s place

Code:

#include <iostream>
#include <cmath>
using namespace std;
void hi (int x)
{
double counter=2;
double i=1;
double binary;
double number=0;
while(x!=0)
{
binary=((x%2)*i);
number=number+binary;
i=pow(10,counter);
counter++;
x=x/2;
}
cout<<number;
}
int main ()
{
int x;
cout<<"Enter number: ";
cin>>x;
hi(x);
return 0;
}

Nvm I got it here is the code if any one is interested, it's pretty simple!

Code:

#include <iostream>#include <cmath>
using namespace std;
void hi (int x)
{
double counter=0;
double i=1;
double binary;
double number=0;
do
{
i=pow(10,counter);
counter++;
binary=((x%2)*i);
x=x/2;
number=number+binary;
}
while(x!=0);
cout<<number<<endl;
}
int main ()
{
int x;
cout<<"Enter number: ";
cin>>x;
hi(x);
return 0;
}