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;
         }
}

------------------------------------------------------------------------------

Edited 6 Years Ago by WaltP: Added CODE Tags

All I see is someone barfing out a bunch of improperly-posted code and pleading for help...

1. Use [code] ...code tags... [/code] (click for more info)
2. Properly describe your problem. Without a description, all we can do is take a shot in the dark.

I see alot of mismatched braces ('{' and '}') that are probably causing some errors, but without a better explanation I really can't provide any more suggestions. [edit] oh wait.... they are properly matched, but the formatting makes it almost impossible to see them... see suggestion 1 above

Here's some info on functions. After you read this, please come back and produce a proper post.

Edited 6 Years Ago by Fbody: n/a

Comments
Nicely put, and props for wading through the "mud"
This article has been dead for over six months. Start a new discussion instead.