Outputting the Individual Digits of a Number

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.
you need to share your code...then we can point out where r the mistakes ..
Can anyone point me in the right direction?
multiple modulos and divides by ten.
but number of digit can be different in case of input..
if we handle this thing then % will help us..
but number of digit can be different in case of input..

modulo, divide, repeat until zero.
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.
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.