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


Newest CodeGuru.com Articles:

  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2
  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 12th, 2009, 03:01 PM
    Inori Inori is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    Inori is an unknown quantity at this point (<10)
    Selecting certain part on an entry.

    Hello!
    I'm really new to C++ and I want to write a simple program, that would proccess entered number part by part, but I can't figure out (nor could I find anything on the subject) how to make my program do it.

    For example, it should look like this:

    Enter code: 32101243421
    if <first two digits> < xx, then xx
    if <third and fift digit> > xx, then xx
    if <sum of all digits> > xx, then xx.
    etc.

    Thanks in advance.
    Reply With Quote
      #2    
    Old November 12th, 2009, 04:17 PM
    kempofighter kempofighter is offline
    Member +
     
    Join Date: Aug 2005
    Location: San Diego, CA
    Posts: 733
    kempofighter has a spectacular aura about (150+) kempofighter has a spectacular aura about (150+)
    Lightbulb Re: Selecting certain part on an entry.

    Off the top of my head, I'd suggest reading about the modulo operator which is useful for getting the value of each digit. To shift a decimal number 1 digit to the right simply divide by 10.

    Code:
    int number(121123);
    int nextDigit(0);
    
    nextDigit = number % 10;  // nextDigit becomes 3
    number /= 10;  // number becomes 12112
    You can play around with some loops to figure out each digit and sum them as you go. You could build an array of digits in a loop and then use the array to accomplish all of the other requirements. Good luck!
    Reply With Quote
      #3    
    Old November 13th, 2009, 12:23 AM
    Inori Inori is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    Inori is an unknown quantity at this point (<10)
    Re: Selecting certain part on an entry.

    Thanks!
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:20 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.