calculate the ages of atleast 2 men- birthdays 28 feb, 29 feb (7 july optional).

2 men were born on feb 29, 1984 and feb 28, 1993 respectively. Calculate their ages from current date. (given that 1988 is a leap year).

Conditions required in the code for avoiding wrong or falsified input by any other men:

i) date d<=29 only if m=2 and y=1988+(4*n), where n can be +ve or -ve integer else d<29 when m=2.

ii) d<=31, if m=1, 3, 5, 7, 8, 10, 12.

iii)d<=30, if m=4, 6, 9, 11

iv) y<2000 to exclude kids.

v) m<13.

I will be very grateful if any1 could provide the full code listing these conditions. Thank you.
Last edited on
I would write a function to validate whether the month, day, and year form a valid date. Here's a partial solution, off the top of my head, so it might not even compile, but it should be plenty to get you going:

1
2
3
4
5
6
7
8
9
10
11
12
bool isValidDate(unsigned year, unsigned month, unsigned day)
{
    if (year >= 2000) return false;   // no kids
    switch (month) {
    case 1:
    case 3:
        if (day > 31) return false;
        break;
    }
    // If you get here then it's good
    return true;
}

Can you make this statement for me
cond1:
(m=2&&y=2000-4n) d<=29 if not d<29

cond2
(m=4&&m=6&&m=9&&m=11&&m!=2) d<31 else d<=31 (default)
Topic archived. No new replies allowed.