Question #36459

write a c++ program that takes the current date and date of birth as input and calculates th age.
1

Expert's answer

2013-10-31T14:15:26-0400
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main()
{
    int year, month, day;
    int birthyear, birthmonth, birthday;
    int y, m, d;
    {
        cout <<"---_current date _---\n";
        cout <<"-Enter year-\n";
        cin >> year;
        cout <<"-Enter month-\n";
        cin >> month;
        cout <<"-Enter day-\n";
        cin >> day;
    }
    {
        cout <<"---_Date of birth_---\n";
        cout <<"-Enter year-\n";
        cin >> birthyear;
        cout <<"-Enter month-\n";
        cin >> birthmonth;
        cout <<"-Enter day-\n";
        cin >> birthday;
    }
    y = abs(birthyear - year);
    m = abs(birthmonth - month);
    d = abs(birthday - day);
    if ((birthmonth - month) == 0)
        if ((birthday - day) == 0 || birthday > day)
            m = m + 1;
            y = y + 1;
    cout <<"\n\n" << "---_You to '" << y <<"_---\n";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS