# length of input number

• 06-25-2003
Alabsi
length of input number
I made a loop to return the number of digit entered by a user, but the problem is that loop does not work with big numbers like number which is more than 10 digit, I also used the sizeof() function but it is the same. Is there any Idea how to make it read bigger numbers, Thanks and the loop is :

Code:

``` cout<<"Please enter the number :"<<endl; //getting input     cin>>num;     temp1=num;         count=0;             while (temp1!=0){                      //counting number of digits       temp1=temp1/10;       count=count+1;                  }```
• 06-25-2003
confuted
change the variable type of num. It's probably an int right now - try float or double. (these support decimal places as well)
• 06-25-2003
Or 4294967295 in an unsigned int. ;)
• 06-25-2003
Alabsi
unsigned long
I really used unsigned long for num but the reasult is the same I'm not allowed to use string. Could any body tell me about the constant variable UMAX_LONG please.Thanks for the fast reply
• 06-25-2003
Hammer
Re: unsigned long
Quote:

Originally posted by Alabsi
I really used unsigned long for num but the reasult is the same I'm not allowed to use string.
Use a char array.

Code:

```char input[1024]; cout <<"Enter number:" ; cin >>input;```
Or if you really want to do this with a numeric variable, you'll have to find one big enough. Check your compiler documentation.

To use UMAX_LONG:

cout <<UMAX_LONG <<endl;
• 06-25-2003
Alabsi
UMAX_LONG
Do I have to declare the UMAX_LONG before I use it, or I have to store the num variable in it, could you tell me more about the UMAX_LONG and I do think I can use the char[] array because it is a string. My compiler is g++ for the information.Thanks.
• 06-25-2003
cr_naik
hey...Alabsi,

Why don't you use itoa(), ltoa() functions to convert numeric values to character array and then get length of it instead of using loop for count number of digits ???
• 06-25-2003
Absi
I do not know wheather that involves the use of string library because if so I'm not allowed yet to use it thanks
• 06-25-2003