# Thread: length of input number

1. ## 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;
}```

2. change the variable type of num. It's probably an int right now - try float or double. (these support decimal places as well)

3. Or 4294967295 in an unsigned int.

4. ## 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

5. ## Re: unsigned long

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;

6. ## 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.

7. 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 ???

8. I do not know wheather that involves the use of string library because if so I'm not allowed yet to use it thanks

9. How many digits are you expecting/expected to process? If it is more than the basic 32/64bit types we have already given you, you are going to need compound data types. That being the case, your statement...

>>> I'm not allowed yet to use it

... [the string library] implies this a pretty basic level program we're talking about.

Are you sure you're not trying to hard?

10. If your using a Windows 32 bit system, then chances are your compiler will support a 64-bit integer type (not a standard type though). Usually, the name is either 'long long' or '__int64'.

A compound type is the best solution (as it would be portable, and predictable, and standard compliant), but this usually will work on a 32 bit system.

Popular pages Recent additions