fail to count digit of an integer (fail at 9)
hi guys
I"m new to C++. I'm actually physics major and conducting self-study for visual C++.
Any help will be greatly appreciated ;)
I came across a problem of counting how many digits are there in an input integer.
My code is
Code:
#include <iostream>
using namespace std;
int main()
{
int number;
int digit=0;
cout << "Enter an integer number:";
cin >> number;
cout << endl;
while (number)
{
number /= 10;
digit++;
}
cout << "Number of digit: " << digit << endl;
return 0;
}
It worked well, but as I typed in more-than-9-digit number, the output was just 9
for example:
Input: 1234567890123
output: 9 (supposed to be more than that!)
I kept checking but didn't get any answer!
Can you please help?
thanks!!