hi i just finished my program but it won't do the input as required by me..
some digits are missing and i can't find it out
basically it is a program that ask user's for input integer and base number
here's the coding
Code:
#include <iostream>
#include <cmath>
using namespace std;
void convert(int , int, int, int*); //convert(number, base, length, result)
int len=0, i;
int main()
{
int num, base, *r;
cout<<"\nEnter a number: ";
cin>>num;
cout<<"\nEnter base: ";
cin>>base;
len=(int)log10(num)/log10(base)+1; //Number of digits of the converted number
r=new int [len];
convert(num, base, len, r);
cout<<endl;
for(i=0; i<len; i++)
cout<<*(r+i);
delete [] r;
return 0;
}
void convert(int n, int b, int len, int* res)
{
for(i=0; i<len; i++)
{
*(res+len-i-1)=n%b;
n/=b;
}
}
like this input i put on
Enter an integer: 89
actual answer||||||||||||| My input answer!!!
89 in Base 2 : 1011001>>1001
89 in Base 3 : 10022>>>>022
89 in Base 4 : 1121>>>>>21
89 in Base 5 : 324>>>>>>24
how to solve this problem???
any ideas??