aaronmk2

Thanks

aaronmk2 Junior Poster in Training

I want to print out the letter B, instead I get a blank line. Any tips would be great
[CODE]

include

using namespace std;
void add(string n);

int main()
{
string B;
add(B);

}

void add(string n)
{
if(n.length() <= 1)
{
cout<<n[0]<<endl;
}

}[/CODE]

aaronmk2

Ignore this one, I realized I need to use a double instead on an int

[QUOTE=aaronmk2;1216804]I am trying to use pow(2,a); and I am getting a error 'pow' ambigous call to over load function. I don't understand why, I added the cmath libarary. Here is the code.

[CODE]

include
include

using namespace std;
int binaryToDec(int);
int main()
{

binaryToDec(1110);

return 0;
}
int binaryToDec(int n)
{
int a=0;
int numTotal=0;
if(n%10 == 0){
a++;
numTotal+=0;
}
else if(n%10!=0)
a++;
numTotal+=pow(2,a); //here is where I get the error

binaryToDec(n / 10);
cout<<numTotal<<endl;
return numTotal;
}[/CODE]

any help would be great[/QUOTE]

aaronmk2 Junior Poster in Training

I am trying to use pow(2,a); and I am getting a error 'pow' ambigous call to over load function. I don't understand why, I added the cmath libarary. Here is the code.

[CODE]

include
include

using namespace std;
int binaryToDec(int);
int main()
{

binaryToDec(1110);

return 0;
}
int binaryToDec(int n)
{
int a=0;
int numTotal=0;
if(n%10 == 0){
a++;
numTotal+=0;
}
else if(n%10!=0)
a++;
numTotal+=pow(2,a); //here is where I get the error

binaryToDec(n / 10);
cout<<numTotal<<endl;
return numTotal;
}[/CODE]

any help would be great

aaronmk2

Thanks, makes complete sense

aaronmk2 Junior Poster in Training

I am trying to learn about recursives and found this code on the internet. It works, but am not sure why. Could some one explain to me why this works. I have posted comments by the function to explain what I do not understand.
[CODE]

include

using namespace std;

void printDisplay(int);

int main()
{

printDisplay(5);
printDisplay(900);
printDisplay(1234);

return 0;
}

void printDisplay(int n) //I understand the n is coming from main
{
cout << n % 10; // this takes the number and gives the remainder when divided by 10.
if (n < 10) { //if statement understand this.
cout << endl; //why are you cout an empty line?
return; }//What are we returning.
printDisplay(n / 10);//why are we dividing the number by 10?
}
[/CODE]