Jump to content

C++ Int Length! intlen()

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
int intlen(float start) {

	int end = 0;

	while(start > 0) {

		start = start/10;

		end++;

	}

	return end;

}

This can in handy with a program I made, I could not find anything else that would replicate this!

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Shouldn't it be


[highlight=C++]int intlen(float start) {
int end = 0;
while(start >= 1) {
start = start/10;
end++;
}
return end;
}
[/highlight]

?

Edited by Vswe, 31 August 2009 - 01:25 PM.


#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Isn't that C++ code? Why the PHP code highlighter? :P

[highlight=C++]int intlen(float start) {
int end = 0;
while(start >= 1) {
start = start/10;
end++;
}
return end;
}[/highlight]

EDIT: Vswe changed it, now I just look dumb. :)

Edited by ZekeDragon, 31 August 2009 - 01:56 PM.
See Edit

Wow I changed my sig!

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
What? while (start > 0) and while (start >= 1) is saying the same thing.

#5
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts

chili5 said:

What? while (start > 0) and while (start >= 1) is saying the same thing.

Only in the world of ints. When you're dealing in floats, a number can be both greater than 0 and less than 1. :P
Wow I changed my sig!

#6
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Oh of course. I wasn't thinking. :) It's a very useful function. :) I'll have to try it out when I get a few minutes. :D

#7
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Thanks guys! I should have realized that one :P