#include <iostream>
#include <string>
using namespace std;
int count_number_place(int number)
{
int number_placement;
while (number >= 1)
{
number_placement++;
cout << number_placement <<endl;
number/=10;
}
return number_placement;
}
int main(int argc, const char * argv[])
{
// insert code here...
int user_input_number;
cout << "Please enter your number here" << endl;
cin >> user_input_number;
cout << "User input number is "<< user_input_number <<endl;
cout << "The numbers of digits in the input number is :" << count_number_place(user_input_number) << endl;
return 0;
}
I'm trying to create a small program that calculates the number of digits of a given number.
Whenever I type in numbers like 200
the expected results is 3
. Instead I got 7963
. When I put a breakpoint at the line number_placement
I got a default value of 7961
which is weird because that value wasn't assigned anywhere in the code.
Can you please explain why I get that result?