i have an assignment:
Write a recursive function that will compute the value of
a representation of a number in given base.
int base(char num[], int radix);
For example, calling the function as
base("1011", 2)
should return 11, but calling it as
base("1011", 10)
should return 1011.
i need to support bases 2–36. “Digits” greater than
9 are encoded as lowercase or uppercase letters. E.g.,
base("Cafe", 16)
returns 51966 = 12 · 163 + 10 · 162 + 15 · 161 + 14 · 160.
i can not use loops or string / math library functions.
i will probably need a helper recursive function.

now, i think that the helper function should calculate the power of the base and add it to the base function , but i dont know how to do it

>but i dont know how to do it
How do you know? Have you already tried it?
If not so, please do so, according to Daniweb's homework policy you should first show your own effort :)

Start with this:

#include <iostream>
using namespace std;

int main()
{

}

To start with this routine must do, build on it.

function
{
sum+=function(string[i+1])*pow(base,i);
return sum;
}

This is not a functional code, work on it. See the pattern and try it yourself. :)

To start with this routine must do, build on it.

function
{
sum+=function(string[i+1])*pow(base,i);
return sum;
}

This is not a functional code, work on it. See the pattern and try it yourself. :)

When do you think that the program stops executing after one call to this 'function' ?

When do you think that the program stops executing after one call to this 'function' ?

I never said this is functional. Just to give him an idea to start.

I never said this is functional. Just to give him an idea to start.

That's pretty strange, you give him a start (in some 'pseudo code'), but you don't mention the pitfalls :P
I know that it's not working, but if you just turn this code into valid C code then your program will just execute until your pc collapses :P
If you want to give him a good start, then you at least have to give him some good pseudo code as well (if you're giving pseudo code).

Edit:: It might be possible that you did know that pitfall, but probably the OP doesn't know that, and this is his thread right? So I hope it doesn't hurt you that I still mention something like that :P

Seems like the OP isn't very interested in being helped?

commented: Strange that, it happens a lot ;) +36

yeah, think so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.