There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
C++ simple question


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
The G-man's Avatar
Senior Member with 133 posts.
 
Join Date: Jun 2001
14-Oct-2003, 01:05 PM #1
Question C++ simple question
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!
Gibble's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
14-Oct-2003, 02:05 PM #2
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's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
14-Oct-2003, 02:08 PM #3
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's Avatar
Senior Member with 133 posts.
 
Join Date: Jun 2001
14-Oct-2003, 02:16 PM #4
Talking thanks Gibble
Thanks for your help. I figured that there was a fairly simple way!
Gibble's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
14-Oct-2003, 03:37 PM #5
No problem
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:18 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.