this is my while code and i use DEV-c++ compiler
and i want to make it as a function and i dont know how ???
and realy want it as soon as possiple because the dead line is tomorrow
------------------------------------------------------------------------------
#include <iostream>
#include <math.h>
using namespace std;
int binTodec (int num1,int num2);
int main ()
{
int num1,num2,i=0,j=0,sum1=0,sum2=0;
cout<<"enter two binary numbers :";
cin>>num1>>num2;
while (num1/10.0!=0 || num2/10.0!=0){
sum1=sum1+(num1%2)*((int)ceil(pow(2,i)));
i++;
num1=num1/10;
sum2=sum2+(num2%2)*((int)ceil(pow(2,j)));
j++;
num2=num2/10;
}
cout<<"converted to binary is : "<<sum1<<" "<<sum2<<endl;
system ("pause");
return 0;
}
-----------------------------------------------------------------------------------
also I will let you see my function code trasformation to tell me what to do
-----------------------------------------------------------------------------------
#include <iostream>
#include <math.h>
using namespace std;
int bin2dec (int x);
int main ()
{
int num1;
cout<<"enter a binary number :";
cin>>num1;
cout<<num1<<" Converted to decimal is : "<<bin2dec(num1)<<endl;
system ("pause");
return 0;
}
int bin2dec (int x){
int i=0,j=0,sum1=0,num1;
int Dnum1=bin2dec(num1);
while (num1/10.0!=0){
sum1=sum1+(num1%2)*((int)ceil(pow(2,i)));
i++;
num1=num1/10;
return sum1;
}
}
------------------------------------------------------------------------------