无法在 for 循环中的 pow 函数上输出答案

can't output answer at pow function in for loop

本文关键字:函数 pow 输出 答案 for 循环      更新时间:2023-10-16

练习是"输入号A,B和A数字列表c。" a"表示列表C的基础," B"表示将列表C转到基于" B"的数字列表。示例:a = 2,b = 3,c = 10110答案是" 211"

这是我的程序:

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int a,b; 
int account, d, size, sum = 0;
char *c, *w;
cout<<"Input two stander a b first, them input a based listed"<<endl; 
cin>>a>>b;
cin.ignore();
cin.getline (c,64);
size = strlen(c);   
d = atoi(c);
for(int i = 0;  i<size; i++){
    account = (d%a)*pow(a,i);
    sum+=account;
    d = (d/a);
}
w = itoa(sum, w, b);
cout<<"the list after transfer:  "<<w<<endl; 

return 0;
}

我的程序可以通过编译器出现,但是我的计算机无法掩盖数据。我焦急地不知道我的程序在哪里错了。我认为这可能是for循环的功能。有人可以帮我吗?

我复制了您的代码并进行了两个更改:而不是char *c, *w; -> char C [256],W [256];(我的编译器抛出了例外,在这里不喜欢 *C(

而不是w = itoa(sum,w,b(; -> _itoa_s(sum,w,b(;

我使用2 3 101对其进行了测试,并获得了"转移12后列表"。希望这项工作。

但是,仍然有警告"从双重转换到int",应将其视为错误。