Dec 13, 2012 at 8:09pm Dec 13, 2012 at 8:09pm UTC
At line 33 cout<<sum;
the variable is output but it was never initialised, so the output is unpredictable.
At line 66 return sum;
a value is returned from the function, but when the function is called on line 31 nothing is done with this result.
Last edited on Dec 13, 2012 at 8:11pm Dec 13, 2012 at 8:11pm UTC
Dec 13, 2012 at 8:11pm Dec 13, 2012 at 8:11pm UTC
ok I know that. but whybut when the function is called on line 31 it does not do anything with this result.
Last edited on Dec 13, 2012 at 8:13pm Dec 13, 2012 at 8:13pm UTC
Dec 13, 2012 at 8:15pm Dec 13, 2012 at 8:15pm UTC
Lets say you want to find the square root of 25.
sqrt(25.0);
will do that.
But if you want to make use of the result you either need to display it directly
cout << sqrt(25.0);
or assign the result to a variable
double x = sqrt(25.0);
The same applies to the function you wrote yourself.
Dec 13, 2012 at 8:28pm Dec 13, 2012 at 8:28pm UTC
thank you so much...
I solved that problem but I think that this program has many problem yet.
thank you anyway
Dec 14, 2012 at 6:33am Dec 14, 2012 at 6:33am UTC
How can I get very long number in this program?
for example:0111100000000000011111111111101
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
// check 4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<cmath>
using namespace std;
void BinarytoDecimal();
int checkbinary(int );
int _tmain(int argc, _TCHAR* argv[])
{
BinarytoDecimal();
}
void BinarytoDecimal()
{
long int number,sum;
static int i=0;
cout<<"Enter the binary number:" ;
cin>>number;
cout<<checkbinary(number);
}
int checkbinary(int number)
{
int remain,i,counter;
double power,sum=0;
const int arreysize=1000;
int binarrey[arreysize];
for (i=0;number!=0;i++)
{
remain=number%10;
number=number/10;
if (remain>1)
{
cout<<"the number is wrong.please try again!" ;
BinarytoDecimal();
}
else
binarrey[i]=remain;
}
for (counter=0;counter<i;counter++)
{
power=counter;
sum=pow(2,power)*binarrey[counter]+sum;
}
return sum;
}
//*********************************************
Last edited on Dec 14, 2012 at 6:42am Dec 14, 2012 at 6:42am UTC
Dec 14, 2012 at 6:58am Dec 14, 2012 at 6:58am UTC
I would make number
a string instead of a long int.
Dec 14, 2012 at 7:09am Dec 14, 2012 at 7:09am UTC
ok,I didn't can use this.
can you explain more?
in checkbinary function it makes problem and I don't know what to do!!!!!!!!!!!
what aboat arrey?
What shoud I do if I want solve it with arrey?
Last edited on Dec 14, 2012 at 7:32am Dec 14, 2012 at 7:32am UTC
Dec 14, 2012 at 2:17pm Dec 14, 2012 at 2:17pm UTC
If I just want to use arrey what shoud I do?(I shoudn't use string)
who knows?????
Dec 14, 2012 at 5:09pm Dec 14, 2012 at 5:09pm UTC
thank you.
but "without using string"!!!!!!!!!!!