Hey guys I was just wondering what you guys think the best way to find the length of an int is. I worked out a nice and easy way to do it my way is shown below. If you guys have your own ways or a better way tell me about it I want to see how well I'm doing in learning C++. Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int findIntLength(longlong number) {
int digits = 0;
longlong tens = 1;
while (number >= tens) {
tens *= 10;
digits++;
}
return (digits);
}
I don't understand how to use that one... I put it in a program but when I fed it a 3 digit number it spit out 49. I'm not sure where it got that =P but mine works better in my opinion.