Answer to Question #282807 in C++ for Suman

Question #282807

The customer should be born on or before july 22 1987




The month of D.O.B should be of 21 days

1
Expert's answer
2022-01-20T01:46:02-0500
#include <stdio.h>
#include <stdlib.h>


using namespace std;


void calcAge(int datee, int monthh,
            int yearr, int birth_date,
            int birth_month, int birth_year)
{
    int month[] = { 31, 28, 31, 30, 31, 30, 31,
                        31, 30, 31, 30, 31 };


    if (birth_date > datee) {
        datee = datee + month[birth_month - 1];
        monthh = monthh - 1;
    }


    if (birth_month > monthh) {
        yearr = yearr - 1;
        monthh = monthh + 12;
    }


    int final_date = datee - birth_date;
    int final_month = monthh - birth_month;
    int final_year = yearr - birth_year;


    printf("Present Age\nYears: %d Months: %d Days:"
        " %d\n", final_year, final_month,
                                    final_date);
}


int main()
{
    int datee = 7;
    int monthh = 3;
    int yearr = 2002;


    int birth_date = 22;
    int birth_month = 7;
    int birth_year = 1987;


    calcAge(datee, monthh, yearr,
            birth_date, birth_month, birth_year);
    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!

Leave a comment

LATEST TUTORIALS
New on Blog