CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Thread: Newbie in need of help.

1. Junior Member
Join Date
Dec 2008
Posts
2

Newbie in need of help.

Hi all, and thank you in advance for your help.

I've been doing some self study for about a month now and am trying to build a program that displays the additive persistence of an integer. The book I'm using doesn't really have clear instructions on how to do this.

2. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,559

Re: Newbie in need of help.

You need to break the problem down into steps then solve each step.
Where are you stuck?

Why are you asking this in a C++ and a VB forum. Which language are you using?
Last edited by GCDEF; December 16th, 2008 at 02:19 PM.

3. Junior Member
Join Date
Dec 2008
Posts
5

Re: Newbie in need of help.

I think you may C++'s % opperator of some help.

Given two integers, A and B, then A%B gives the remainder of A when divided by B. If you choose B=10, then A%10 will give the last digit of A.

Also in C++ when you divide one integer by a second the result is always rounded down, so A/10 is an integer with the units chopped off.

Put these two ideas together with some while loops and I'm sure you'll get there.

4. Re: Newbie in need of help.

Not unless you ask for some clear directions. For instance, I have no idea what "additive persistence of an integer" means. But then I'm not that good at English math terms.

5. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,559

Re: Newbie in need of help.

Originally Posted by cilu
Not unless you ask for some clear directions. For instance, I have no idea what "additive persistence of an integer" means. But then I'm not that good at English math terms.
It's kind of a goofy concept. Basically given a number, keep summing the digits till you're down to one digit. For example.

2356 = 2 + 3 + 5 + 6 = 16.
1 + 6 = 7
7 is one digit, so you're done.

6. Re: Newbie in need of help.

Originally Posted by genn0226
...I've been doing some self study for about a month now ....Can anyone please help?
While studing one's self is very revealing, studing a programming language is much more appropriate to learning to program.

What book are you using?
What chapter are you up to?
Whave you been following it carefully?
Have your been typing in ALL of the code samples?
Have you been stepping through each line with the debugger?

Having this information will help in proving you withg information that will be understandable, once you provide SPCIFIC information on the exact problem.

7. Re: Newbie in need of help.

Originally Posted by GCDEF
It's kind of a goofy concept. Basically given a number, keep summing the digits till you're down to one digit. For example.

2356 = 2 + 3 + 5 + 6 = 16.
1 + 6 = 7
7 is one digit, so you're done.
Right. I like that. Though I see no value in it. Now I know how it's called.

8. Re: Newbie in need of help.

Here's a suggestion for you:

Treat your input numbers as a character array. Then you can itterate through each number as part of a For loop. You would then cast each array element as an integer and += it to a new variable that would hold your calculation.

Posting Permissions

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

Click Here to Expand Forum to Full Width