dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Newbie in need of help.

  1. #1
    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.

    Can anyone please help?

  2. #2
    GCDEF is offline 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. #3
    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. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Newbie in need of help.

    Can anyone please 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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

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

    Re: Newbie in need of help.

    Quote Originally Posted by cilu View Post
    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. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Newbie in need of help.

    Quote Originally Posted by genn0226 View Post
    ...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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Newbie in need of help.

    Quote Originally Posted by GCDEF View Post
    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Dec 2008
    Posts
    144

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)