1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++ simple question

Discussion in 'Software Development' started by The G-man, Oct 14, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. The G-man

    The G-man Thread Starter

    Joined:
    Jun 3, 2001
    Messages:
    140
    I am writing an app where I want to have the user enter an 8-digit integer value. From that value, I would like to be able to extract certain digits from the number they entered to be used in an algorithm to generate a code. Is there a simple way of doing this without using string functions? I would prefer to manipulate the entered value as a single integer.

    Please help!!!
    Thanks!
     
  2. Gibble

    Gibble

    Joined:
    Oct 9, 2001
    Messages:
    27,087
    12345678

    Take the number

    If I want to find out the value in the 100s spot (6) I can as follows.

    12,345,678 MOD 1000 = 678
    678 MOD 100 = 78
    678 - 78 = 600
    600 / 100 = 6

    So basically, it's a little tricky, but very doable.

    --HTH
     
  3. Gibble

    Gibble

    Joined:
    Oct 9, 2001
    Messages:
    27,087
    Or to reduce that to a single formula should be

    ((X MOD 1000) - ((X MOD 1000) MOD 100)) / 100

    To find the digit in the 1000s spot, just add a 0 to each part of the formula

    ie
    ((X MOD 10000) - ((X MOD 10000) MOD 1000)) / 1000
     
  4. The G-man

    The G-man Thread Starter

    Joined:
    Jun 3, 2001
    Messages:
    140
    Thanks for your help. I figured that there was a fairly simple way!
     
  5. Gibble

    Gibble

    Joined:
    Oct 9, 2001
    Messages:
    27,087
    No problem :)
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/171918

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice