当我运行它时,它根本没有返回任何答案。我无法弄清楚原因。基本上我需要将给定数字的每个数字乘以其基数上升到等于数字的程度。每次运行时功率会减少。或者它应该,无论如何。它没有。
int num, sum, base;
sum = 0;
cout << "num";
cin >> num;
cout << "base";
cin >> base;
int power = 0;
while (num > 0)
{
power++;
num = num/10;
}
return power;
sum = 0 ;
while (num > 0);
{
sum = (num%10)*(pow(base, power));
num = num/10;
power--;
}
sum += sum;
cout << sum;
答案 0 :(得分:3)
查看您的代码,看起来您的函数中间有一个流氓return
语句。至少我假设它是一个函数,因为你的代码中没有正确的函数定义。
将其删除,然后重试!
return power; <-- right here your function will return and no code underneath will be executed
sum = 0 ;
while (num > 0);
{
sum = (num%10)*(pow(base, power));
num = num/10;
power--;
}
sum += sum;
cout << sum;