Hey I have an assignment to get a number from the user and print it as a string with commas in the correct space. For example if the number is 13904 it should read 13,904 or 1005 should read 1,005. I have to do this recursively. Working on my pseudo-code I had two ideas and I got stuck on both ideas. My first idea was to take the number as a variable and enter it into a character array then add a comma in the necessary spots, this seemed easier so it is what I went with. But I could not figure how to put each separate number from the variable in each of their own spots in the array. Any help would be greatly appreciated.
MrHardRock
0
Light Poster
Recommended Answers
Jump to Postto do what you want to do, you would need a second array that is bigger so that you can transfer lets say 3 numbers from the original array and then manually add a comma, rince and repeat. but adding the comma where they belong in the original would cause …
Jump to Postno not really, my paragraph above is BASICLY youre whole pseudo code, but as i was testing it on my side theres a few things i noticed but anyways, the main issue you have to deal with , is that some numbers wont end with 3 numbers left of the …
Jump to PostIn my opinion, you should find this code self-explanatory.
[EDIT: This is not a spoiler, just another way of doing it. Do it yourself once to get the hang of it.]
Oh, plus this code does not handle decimal points. If you want to tackle decimal points too, …
Jump to PostIn my opinion, you should find this code self-explanatory.
[EDIT: This is not a spoiler, just another way of doing it. Do it yourself once to get the hang of it.]
Oh, plus this code does not handle decimal points. If you want to tackle decimal points too, just split …
Jump to PostHaha. You don't expect it to work the first time. It has to have errors, or I'm not human. Let me correct it, wait. :)
it's not about errors , it compiled, i did have to add a -1 to your starting loop value since it was getting an index …
All 17 Replies
Philippe.Lahaie
42
Posting Whiz in Training
MrHardRock
0
Light Poster
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
19
Junior Poster
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
19
Junior Poster
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
commented:
Ya, I wrote that without seeing or checking it twice. My mistake :) Check my next post: you will find that working, I expect. It does not account for decimals, however; but that you must agree with me is easily added.
+3
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
19
Junior Poster
Philippe.Lahaie
42
Posting Whiz in Training
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
19
Junior Poster
Philippe.Lahaie
42
Posting Whiz in Training
stultuske
1,116
Posting Maven
Featured Poster
dantinkakkar
19
Junior Poster
Philippe.Lahaie
42
Posting Whiz in Training
dantinkakkar
19
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.