as********@yahoo.com wrote:
On Sep 18, 9:31 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>aslamhe...@yahoo.com wrote:
>>hem anyone can give me an idea on how to saparated digits using
looping
example
please key in any 5 digits number : 56789
and the ouput is
I'm going to guess that ints on your system can store any 5 digit
number. Otherwise you might have to use a string to store the digits.
I suggest that you not use float for this particular assignment.
[snip]
Ok, in another thread somewhere you posted that the actual output is,
and the ouput is
5678 9
567 89
56 789
5 6789
I'm going to assume that's correct because it makes more sense.
Write down a table of what you need.
You're going to go thru the loop 4 times.
You'll need some number of spaces before your number.
You'll need some number of digits.
You'll need some number of spaces. I'm less sure about this, so I'll
let you figure that out.
More digits.
Make a table like so:
main spaces before leading spaces trailing
index number digits digits
0 0 4 ? 1
1 2 3 ? 2
2 4 2 ? 3
3 6 1 ? 4
Now think about the relationships between those numbers, for example,
starting with a number in main index, what will yield the number in the
same row in the column spaces before number?
Elsewhere you got good advice about how to deal with the numbers in the
leading and trailing digits columns.
Don't use scanf, printf, etc. learn about streams. Learn about std::string.
>>huhu how to saparate those digin huhuhu can help???anyone?
>Treat the number as text and insert spaces at appropriate places.
>>i prefer code in c..
Oh, sorry, I didn't see that before I responded. I agree with the advice
given below.
>Then ask in compl.lang.c and not in a C++ group.
In particular the other problem you were asking about that seemed to be
part of calculating the cost of a meal, will get very different advice
from c and c++ programmers. So asking here may be less than useful for
you if you want to program in c.
OTOH, you may want to ask both c and c++ programmers and decide for
yourself which answers are more pleasing to you.
what ur comment about this code??
Needs to be better formatted.
is thit mean im almost got the
answer??
I don't know. I'm afraid that you'll have to look at the output and
decide that for yourself.
LR