0

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

#include <iostream>
#include <string>
using namespace std;

int main()
{
int idnum,age,yearbirth;

cout << "enter id number: ";
cin >> idnum;

yearbirth=idnum.subint (0,2);

age=2009-yearbirth

cout << age;

}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jonsca
0

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)[B];[/B]

What are you trying to do here?

Edited by VernonDozier: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.