Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,014 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,478 people online right now. Registration is fast and FREE... Join Now!




Integers and sorting

 
Reply to this topicStart new topic

Integers and sorting

ifoam
28 Nov, 2006 - 08:39 PM
Post #1

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
ok, i need to change the integer 1 to be stored as 000001 because i need it to show up as that.

OR i need a way to store 000001 in a string and be able to add 1 to it until 500000.

can anyone help?
User is offlineProfile CardPM
+Quote Post

ifoam
RE: Integers And Sorting
28 Nov, 2006 - 08:47 PM
Post #2

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
btw:

i was thinking of some kind of code like this:

let x be a string and assume x has a number.

if x < 6 characters, add 0's in the front to make it 6.
User is offlineProfile CardPM
+Quote Post

ifoam
RE: Integers And Sorting
28 Nov, 2006 - 08:56 PM
Post #3

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
got it

CODE
while(id.length()<6)
              id="0"+id;

User is offlineProfile CardPM
+Quote Post

ReggaetonKing
RE: Integers And Sorting
28 Nov, 2006 - 09:07 PM
Post #4

D.I.C Head
Group Icon

Joined: 16 Nov, 2006
Posts: 73



Thanked: 1 times
Dream Kudos: 100
My Contributions
I wish I could answer my own question as fast as you did. tongue.gif
User is offlineProfile CardPM
+Quote Post

ifoam
RE: Integers And Sorting
28 Nov, 2006 - 09:23 PM
Post #5

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
haha smile.gif

i have another question!

say i ask to input an integer.

i want to know how many digits the integer has.

for instance if they input 1000000 it should return 7.

input 100 return 3

input 1000 return 4
User is offlineProfile CardPM
+Quote Post

eXceed69
RE: Integers And Sorting
28 Nov, 2006 - 09:31 PM
Post #6

"Super Sentai Knight Of DawN"
Group Icon

Joined: 12 Nov, 2006
Posts: 682



Thanked: 1 times
Dream Kudos: 675
My Contributions
hmm..store to a string...then had then had strlen
User is offlineProfile CardPM
+Quote Post

ifoam
RE: Integers And Sorting
28 Nov, 2006 - 10:05 PM
Post #7

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
duh! thanks
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 09:01PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month