Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用递归将数字转换为具有不同基数的另一个数字?_C++_Recursion - Fatal编程技术网

C++ 使用递归将数字转换为具有不同基数的另一个数字?

C++ 使用递归将数字转换为具有不同基数的另一个数字?,c++,recursion,C++,Recursion,我正在使用递归将一个数字转换成另一个具有不同基数的数字,但我的代码中存在一个问题。我的代码不符合我的要求。请检查并告诉我问题出在哪里? 谢谢 #包括 使用名称空间std; int基函数(int,int); int main() { 整数,基数; 库特号码; coutbase; coutcoutnumber; coutbase; 虽然你的思维方向正确,但你在逻辑上犯了一个小错误 if(n==1) return n; else { baseFunction(n/b,b); c

我正在使用递归将一个数字转换成另一个具有不同基数的数字,但我的代码中存在一个问题。我的代码不符合我的要求。请检查并告诉我问题出在哪里? 谢谢

#包括
使用名称空间std;
int基函数(int,int);
int main()
{
整数,基数;
库特号码;
coutbase;
cout
coutnumber;
coutbase;

虽然你的思维方向正确,但你在逻辑上犯了一个小错误

if(n==1)
    return n;
else
{
    baseFunction(n/b,b);
    cout<<n%b;
}
if(n==1)
返回n;
其他的
{
基本功能(n/b,b);

coutNumbers没有“基数”。你手上手指的基数是多少?基数可以是3、8、16等。数字没有基数;数字的文本表示有基数。谢谢你的回答。你能给我这个程序的正确代码吗?
cout<<"Enter number: ";
//enters NUMBER
cin>>number;
cout<<"Enter base: ";
//enters BASE
cin>>base;
cout<<"OutPut "<<number<<" is ";
//function, that returns int, returns it to nothing, so nothing changes
baseFunction(number,base);
//BASE unaffected, since function did nothing
cout<<" in base "<<base<<endl;
if(n==1)
    return n;
else
{
    baseFunction(n/b,b);
    cout<<n%b;
}
    if(n>0)
    {
        baseFunction(n/b,b);
        cout<<n%b;
    }
    else
    {
        return;
    }