Funkcja otrzymuje docelowo dodatnią liczbę całkowitą (n) i system liczbowy (p), ma zwrócić liczbę n w systemie p, jako string. Ktoś mi powie dlaczego, to nie chce działać, bo kompletnie nie rozumiem?
#include <iostream>
#include <string>
using namespace std;
string funkcja(unsigned int, unsigned int);
int main()
{
unsigned int n, p;
cout << "Podaj liczbe: ";
cin >> n;
cout << "Podaj podstawe systemu: ";
cin >> p;
cout << n << " = ";
cout << funkcja(n,p) << " w systemie " << p << endl;
return 0;
}
string funkcja(unsigned int n , unsigned int p )
{
int pom=n;
int licz=0;
while(pom>0)
{
pom/p;
licz++;
}
int *tab=new int [licz];
int a=n;
for(int i=0; i<licz; i++)
{
tab[i]=n%a;
a=n/p;
n/=p;
}
string tablica;
int j=0;
for(int i=(licz-1); i>0;j++, i--)
{
tab[i]=tablica[j];
}
delete [] tab;
return tablica;
}