C++ program that asks the user to enter his age in days
#include <iostream>
using namespace std;
void Findage() //Defining function
{
int a=0,d=0, m=0, y=0, r=0;
cout<<"Enter Age in Days= "; //Taking input
cin>>a;
if(a>365) //If age is greater than 365
{
y=(a)/365;
r=a%365;
if(r>30)
{
m=r/30;
d=r%30;
}
else
{
d=r%30;
}
}
else //if the age is less than 365
{
if(a>30)
{
m=(a)/30;
d=a%30;
}
else
{
d=a;
}
}if(a==365) //Printing output
{ cout<<"Your Age in Calender"<<endl;
cout<<"Year = 1"<<endl;
}
else
{
cout<<"Your Age in Calender"<<endl;
cout<<"Years= "<<y<<" Month="<<m<<" Days= "<<d<<endl;
}
}
int main()
{
Findage(); //Calling function
return 0;
}
Output
Enter Age in Days= 3697
Your Age in Calender
Years= 10 Month=1 Days= 17