Outputting the Individual Digits of a Number

Nov 5, 2012 at 2:52pm
Hello! First post, bear with me please.

I'm working on a homework assignment. This is the exercise:

"Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of 3456 as 3 4 5 6."

I am able to have the program output the sum of the digits, but I cannot seem to find out how to separate the digits as demonstrated.

Can anyone point me in the right direction?

Much appreciated.
Nov 5, 2012 at 2:59pm
you need to share your code...then we can point out where r the mistakes ..
Nov 5, 2012 at 3:06pm
Can anyone point me in the right direction?
multiple modulos and divides by ten.
Nov 5, 2012 at 3:13pm
but number of digit can be different in case of input..
if we handle this thing then % will help us..
Nov 5, 2012 at 3:17pm
but number of digit can be different in case of input..

modulo, divide, repeat until zero.
Nov 5, 2012 at 3:20pm
you need to share your code...then we can point out where r the mistakes ..


The code does not exist, as I do not have the slightest clue how it should look.
Nov 5, 2012 at 3:43pm
You say that you can manage to find the sum of the digits, so I assume you already know how to implement the loop that LowestOne is talking about.

Just add another step to your loop that outputs each digit to a string stream as they come out. Then output the string after the loop is over.
Topic archived. No new replies allowed.