how to display 12345 as 12,345 ??

P

pembed2003

John Harrison said:
Its not a rule, but its obviously a good idea if you want to get help.

If you submit partial code, then there is a good chance that people won't be
able to answer the question because you missed out some vital piece of
information. Its amazing how many posters, despite not understand why their
code doesn't work are convinced that they know where the mistake is in their
code. Eventually when you get them to post more code, you often find that
the real error was in some part of the code they didn't originally post.

Hi John,
Yes I understand that but my confusion is not when people asking
question, it's when people post an answer to a question. If OP asks a
solution for a function to display a number in a certain format, do
you normally give OP a whole program or just the function that does
it?

Thanks!
 
J

John Harrison

pembed2003 said:
Its not a rule, but its obviously a good idea if you want to get help.

If you submit partial code, then there is a good chance that people won't be
able to answer the question because you missed out some vital piece of
information. Its amazing how many posters, despite not understand why their
code doesn't work are convinced that they know where the mistake is in their
code. Eventually when you get them to post more code, you often find that
the real error was in some part of the code they didn't originally post.

Hi John,
Yes I understand that but my confusion is not when people asking
question, it's when people post an answer to a question. If OP asks a
solution for a function to display a number in a certain format, do
you normally give OP a whole program or just the function that does
it?

Thanks![/QUOTE]

I think it depends a lot on the complexity of the answer. If it was
something I was pretty sure I could type in without any serious error then I
would just post it and say 'untested code'. On the other hand if it was
something I had to compile and test to be confident I was right, then I
would do that and cut and paste the whole program. The former is more common
than the later for me and the sort of questions I answer. Not sure about
others tho'.

You can be pretty sure that if you do post code in an answer and it's wrong
it will get picked up on, and if you didn't say 'untested code' you could
easily get flamed. A lot of people (like me for instance) try to get newbies
to post complete compilable programs (they rarely listen) so it's a bit
inconsistent to then post incomplete uncompilable answers.

john
 
R

rossum

void _display_number(int v, int n){
[snip]
The second parameter is a yes/no flag so it is better to declare is as
a bool which gives a better indication of its purpose. It is possible
to eliminate this parameter by taking a slightly different approach to
the recursion.

Yes. Totally agree. Can you show me how?

I assume that you know how to declare a bool and are asking about
eliminating the second parameter.

I could be cruel and just say that you will learn better by working
that sort of thing out for yourself, however I will give you three
hints:

1 Since the negative sign always comes at the start of the output then
it is possible to deal with it before starting work on the rest of the
number.

2 The negative sign has no effect on the distribution of commas, so
once the sign has been dealt with then printing a negative number is
going to be identical to printing the corresponding positive.

3 If you are still stuck then it may be useful to look at the various
bits of code posted in this thread for ideas.

Once you have worked that out, you can think about something similar
for the '\n' that was causing problems.

rossum
 
S

Siemel Naran

Dietmar Kuehl said:
std::locale myloc(std::locale(), new mynumpunct);

As an aside, how do you create a locale containing many facets? Example of
what I want:

std::locale myloc(std::locale(), new mynumpunct, new myspace);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,913
Members
47,455
Latest member
Delilah Code

Latest Threads

Top