Please help me my teacher gave me a program and I don't know how to do it. So this the program the she gave me.
"Conversion from any Base to Base 10". Please help me :(

Do you know how to do this on paper? Do you understand what is meant by a number being in a base other than base 10?

Yeah I know this on paper. But making a program with it I can't. And my teacher said it should be in array.

learning to do it in code is what you're taking those classes for. So go ahead and try...
If you just wait for others to do it for you and hand in what they have done as your own you've learned nothing except how to be a dishonest, cheating, lazy, profiteering, liar.

Heres's my program and I don't if this right or wrong. And plus I need this to be in array.

#include<iostream.h>
#include<conio.h>
int convert(int a,int base)
{
int sum=a%10;
for(int i=base;(a/=10)!=0;i*=base)
sum+=a*i;
return sum;
}

int main()
{
    int a,base,ans;

    cout << "Enter a number: ";
    cin >> a;

    cout << "Enter a base: ";
    cin >> base;

    ans=convert(a,base);

    cout << "the converted base 10 is"<<ans;
    getch();
    return 0;
}   

Here, this should pretty much clear everything uncertain about converting any number to base 10: Click Here

Also, your function is wrong, don't rush through steps, it will get you confused:

#include <cmath>
int ToBase10(int number, int base){
    int ret = 0;                        //return number;
    for (int i = 0; i < base; i++){     //loop for computing the base power
        //add to your number the last digit raised to base^i
        ret += number % 10 * std::pow((double)base, (double)i);
        number /= 10;                   //slice the last digit
    }
    return ret;
}
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.