# C++ simple question

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

#### The G-man

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.

Thanks!

#### Gibble

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

#### Gibble

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

#### The G-man

Thanks for your help. I figured that there was a fairly simple way!

#### Gibble

No problem

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

As Seen On