Simplifying my program to convert numbers to from one base to another
<p>I'm taking a beginner C++ course. I received an assignment telling me to write a program that converts an arbitrary number from any base between binary and hex to another base between binary and hex. I was asked to use separate functions to convert to and from base 10. It was to help us get used to using arrays. (We already covered passing by reference previously in class.) I already turned this in, but I'm pretty sure this wasn't how I was meant to do it:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &lt;cstring&gt;
#include &lt;cmath&gt;

using std::cout;
using std::cin;
using std::endl;

int to_dec(char value[], int starting_base);
char* from_dec(int value, int ending_base);

int main() {
    char value[30];
    int starting_base;
    int ending_base;
    cout &lt;&lt; "This program converts from one base to another, so long as the bases are" &lt;&lt; endl
        &lt;&lt; "between 2 and 16." &lt;&lt; endl
        &lt;&lt; endl;
input_numbers:
    cout &lt;&lt; "Enter the number, then starting base, then ending base:" &lt;&lt; endl;
    cin &gt;&gt; value &gt;&gt; starting_base &gt;&gt; ending_base;
    if (starting_base &lt; 2 || starting_base &gt; 16 || ending_base &lt; 2 || ending_base &gt; 16) {
        cout &lt;&lt; "Invalid base(s). ";
        goto input_numbers;
    }
    for (int i=0; value[i]; i++) value[i] = toupper(value[i]);
    cout &lt;&lt; "Base " &lt;&lt; ending_base &lt;&lt; ": " &lt;&lt; from_dec(to_dec(value, starting_base), ending_base) &lt;&lt; endl
        &lt;&lt; "Press any key to exit.";
    getch();
    return 0;
}

int to_dec(char value[], int starting_base) {
    char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    long int return_value = 0;
    unsigned short int digit = 0;
    for (short int pos = strlen(value)-1; pos &gt; -1; pos--) {
        for (int i=0; i&lt;starting_base; i++) {
            if (hex[i] == value[pos]) {
                return_value+=i*pow((float)starting_base, digit++);
                break;
            }
        }
    }
    return return_value;
}

char* from_dec(int value, int ending_base) {
    char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    char *return_value = (char *)malloc(30);
    unsigned short int digit = (int)ceil(log10((double)(value+1))/log10((double)ending_base));
    return_value[digit] = 0;
    for (; value != 0; value/=ending_base) return_value[--digit] = hex[value%ending_base];
    return return_value;
}
</code></pre>

<p>I'm pretty sure this is more advanced than it was meant to be. How do you think I was supposed to do it? </p>

<p>I'm essentially looking for two kinds of answers:</p>

<ol>
<li>Examples of what a simple solution like the one my teacher probably expected would be.</li>
<li>Suggestions on how to improve the code.</li>
</ol>
