I want to print out the letter B, instead I get a blank line. Any tips would be great
[CODE]
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]
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]
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]
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]
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
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]
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]