Homework Help! Probably very easy...
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Homework Help! Probably very easy...

1. Junior Member
Join Date
Sep 2009
Posts
1

## Homework Help! Probably very easy...

I have been doing this homework since the day it was assigned and I have 3 problems left out of 11 with absolutely no clue on how to do them.

Here's one of them..

It wants me to write a program that prompts the user to input an integer and then output 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, output the individual digits of 8030 as 8 0 3 0, output the individual digits of 2345526 as 2 3 4 5 5 2 6, output the individual digits of -2345 as 2 3 4 5.

It seems like it would be very easy but I just can't seem to come up with what to do and my professor won't pick up his phone! LOL =[

2. Elite Member Power Poster
Join Date
Oct 2007
Location
Seattle, WA
Posts
10,895

## Re: Homework Help! Probably very easy...

There are two ways to approach this sort of problem.
1) Use modular math to identify each individual digit sequentially, eg, n &#37; 10 is the ones digit of n.
2) Convert the integer to a string (multiple approaches---stringstream, itoa, sprintf, etc) and then just process the resulting string. Be careful to recognize the difference between the character '1' and the number 1 when adding the digits, though!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•