Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple birthday Program.

Started by Crzyone9584 Jan 16, 2007 at 12:44 AM 4 replies 850+ views
Original Post
Crzyone9584
Crzyone9584
Well i shouldnt say simple. It was in the beginning now i would like to get it to be more exact. This is what I'm trying to do. I would like the program I'm making to say your exact age to teh very second. Here is what i have so far. #include void main(void) { string name; int year; int dob; int sum; cout << "Enter First Name: "; cin >> name; cout << "Enter Current Year: "; cin >> year; cout << "Enter Date Of Birth: "; cin >> dob; sum = year - dob; cout << "Your Name is " << name; cout << "\nYour Age is " << sum << endl; } Please note that I turned a basic addition porgram in my c++ book into this with no knowledge what so ever. But i would like it to have you Input the month day and year for currnt year and bod. and then later on add some more advanced tools to this and a graphical interface. As of right now its all through the cmd windowl.
Living to Play, Playing to Live
Crzyone9584
Crzyone9584
Thats what im asking. how would i have the correct date format. mm/dd/yyyy as input and subtracted right?
Living to Play, Playing to Live
Fase
Fase
You either need to parse your dob string(which is currently an int and won't fly), or have it entered in lose chunks, like, month, day , year.

At the moment you are trying to store dob as a type of int.
int dob;...cout << "Enter Date Of Birth: ";cin >> dob;

This means only numerical values can be entered, so mm/dd/yy is out of the question.

Maybe you can break it up like:
int yearOfBirth;int monthOfBirth;int dayOfBirth;cout << "Enter Year Of Birth: ";cin >> yearOfBirth;etc


If this does not make sense to you, try some easier stuff first where data types are explained.

Look at all the pretty colours!
Crzyone9584
Crzyone9584
That makes since to me. But now would i change the current to to the samething? and then just have a more advanced math problem to get the exact age?
Living to Play, Playing to Live

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.