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

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!
 
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
 
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
 
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.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Top