无法从C ++中的函数获得正确的输出

时间:2015-03-08 07:39:22

标签: c++

我希望代码是自我解释的。

#include <iostream>
#include <cmath>
using namespace std;
int digits(int inp); //Prototyping correct?

int main()
{
    cout << digits(10);//I intend to have a cin statement here
                       //Set to a constant for checking, getting 24683872. Expected 2.
}

int digits(int inp)
{
    float a = 10;
    int i = 1;
    int n;
    int m_d = 1 ;
    while (m_d >= 1) //Keeps dividing by higher powers of 10 to find digits.
    {
        n = int(pow(a, i));
        m_d = inp / n;
        i++;
    }
    cout << (i-1);
}

0 个答案:

没有答案