Answer to Question #289528 in C++ for muaaz

Question #289528

you have to create a program that shall determine the age of the user.


1
Expert's answer
2022-01-24T08:04:47-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

#include <iostream>
#include<vector>

using namespace std;


//you have to create a program that shall determine the age of the user.
unsigned long DoBDD,DoBMM,DoBYY;
unsigned long EndDD,EndMM,EndYY;
unsigned long dd,mm,yy;
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};




 int month(int a,int yy)
  {
  int x=0,c;
  for(c=0;c<a-1;c++)
    {
   if(c==1)
      {
      if(yy%4==0)
      x+=29;
      else
      x+=28;
      }
    else
    x+=mon[c];
    }
  return(x);
  }


int days(int y1,int y2,int m1,int m2,int d1,int d2)
  {
  int count=0,i;
  for(i=y1;i<y2;i++)
    {
    if(i%4==0)
    count+=366;
    else
    count+=365;
    }
  count-=month(m1,y1);
  count-=d1;
  count+=month(m2,y2);
  count+=d2;
  if(count<0)
  count=count*-1;
  return(count);
  }






void GetDate(void)
{
	int LeapFlag=0;
	yy=2101; mm=13; dd=33;
	while(yy<1900 || yy>2100) {cout<<"\nEnter the Year (1900 to 2100) : "; cin>>yy;}
    if(yy%4 == 0)
    {
        if( yy%100 == 0)
        {
            if ( yy%400 == 0)	LeapFlag=1;
            else				LeapFlag=0;
        }
        else	LeapFlag=1;
    }
    else	LeapFlag=0;
	while(mm<1 || mm>12) 	  {cout<<"\nEnter the Month(1-12)         : "; cin>>mm;}
	while(dd<1 || dd>31) 	  {cout<<"\nEnter the Date (1-31)         : "; cin>>dd;}
}










main(void)
{
	unsigned long No_of_Days,Min,Hrs;
	cout<<"\n\nEnter Date of Birth: "; GetDate();
	DoBDD=dd;	DoBMM = mm;	DoBYY = yy;
	cout<<"\n\nEnter End Date: "; GetDate();
	EndDD = dd;	EndMM = mm;	EndYY = yy;
	
	No_of_Days = days(DoBYY, EndYY,DoBMM,EndMM,DoBDD,EndDD);
	yy = No_of_Days/365;
	mm = (No_of_Days%365)/30;
	dd = (No_of_Days%365)%30;
	cout<<"\n\nThe age is: "<<yy<<" Years "<<", "<<mm<<" Months and "<<dd<<" days.";
	
	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