|
-
Sep 27th, 2002, 03:35 PM
#1
Thread Starter
Member
calculating someones age
I am trying to calculate the age of someone. I am having the user input his age as a string, but I was just doing year they were born. However i need it to calculate the date to ensure that it is before or after there birthday to get the correct age of the user. How do i compare to dates to find the users age? I am at a stand still on this, any help appreciated.
-
Sep 27th, 2002, 11:58 PM
#2
Hyperactive Member
well you could ask them to enter their month in numeric form (ie. jan = 1, feb = 2, mar = 3... etc)
Code:
// "u" is for user, "t" is for today's
int u_year, u_mouth, u_day;
int t_year, t_month, t_day;
if ((u_month <= t_month) && (u_day <= t_day))
// already had their birthday
{return (u_today - t_day);}
else
// haven't had their birthday
{return (u_today - t_day - 1);}
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Sep 30th, 2002, 07:52 AM
#3
Hyperactive Member
Hey Cap'n
not sure if your if works
it requires the month and day always to be less than.
Shouldn't it be
Code:
if(u_month < t_month || (u_month==t_month && u_day<=t_day))
{
// already had their birthday
}
else
{
// haven't had their birthday
}
-
Sep 30th, 2002, 02:42 PM
#4
Hyperactive Member
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Sep 30th, 2002, 03:21 PM
#5
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|