is that possible i'm using this substring to determine age from id?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 59
Reputation: samsons17 is an unknown quantity at this point 
Solved Threads: 1
samsons17 samsons17 is offline Offline
Junior Poster in Training

is that possible i'm using this substring to determine age from id?

 
0
  #1
Nov 3rd, 2009
i'm trying to determine the age of the people by entering their id card number..i'm trying to do this without having the database..
is this code possible??because i got error when try to run it..
if this possible,could you tell me the correct way to do this?

Thanks...

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int idnum,age,yearbirth;
  8.  
  9. cout << "enter id number: ";
  10. cin >> idnum;
  11.  
  12. yearbirth=idnum.subint (0,2);
  13.  
  14. age=2009-yearbirth
  15.  
  16. cout << age;
  17.  
  18. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
0
  #2
Nov 3rd, 2009
I think you need to give an example. What's idnum? How does one determine yearbirth from idnum? idnum is an int. There's no "int" class, so the dot operator won't work.

idnum.subint (0,2);

What are you trying to do here?
Last edited by VernonDozier; Nov 3rd, 2009 at 12:37 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 455
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 52
jonsca jonsca is offline Offline
Posting Pro in Training
 
0
  #3
Nov 3rd, 2009
There's no such thing as subint to my knowledge.
Take in the ID as a string, do a substr(0,2), convert that truncated string to an integer (using atoi). There's a slight flaw in your ID scheme though since if the digits are 00-09 the person could be 100 or just born. You need to do your subtraction by adding to your year value so it gives the right age.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC