I have to solve it with borland C++
How can I write a progam that calculate age from current date to:year, month,day,hour?? (cosidering leap year?
Something like this?
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;iostream.h%26gt;
#include%26lt;time.h%26gt;
#include%26lt;alloc.h%26gt;
#include%26lt;math.h%26gt;
char months[12][3]={"Jan","Feb","Mar","Apr","...
void main()
{
clrscr();
int j,d,m,y,day=0,month,year=0;
char ch;
char *p;
time_t tnow;
time(%26amp;tnow);
p=(char *)malloc(sizeof(tnow));
p=ctime(%26amp;tnow);
for(month=0;month%26lt;12;month++)
if(months[month][0]==p[4])
if(months[month][1]==p[5])
if(months[month][2]==p[6])
{
month++;
break;
}
for(j=0;j%26lt;4;j++)
year=(year*10)+abs(48-(int)p[j+20]);
day=abs(48-(int)p[8])*10+abs(48-(int)p...
wrong:
cout%26lt;%26lt;"enter the date of birth::";
cin%26gt;%26gt;d%26gt;%26gt;ch%26gt;%26gt;m%26gt;%26gt;ch%26gt;%26gt;y;
if(!(d%26gt;=1 %26amp;%26amp; d%26lt;=31 %26amp;%26amp; m%26gt;=1 %26amp;%26amp; m%26lt;=12)||(y%4==0 %26amp;%26amp; m==2 %26amp;%26amp; d%26gt;29) || (y%4!=0 %26amp;%26amp; m==2 %26amp;%26amp; d%26gt;28))
{
printf("You have entered wrong data\n");
goto wrong;
}
cout%26lt;%26lt;"Your current age is"
if(m%26lt;=month %26amp;%26amp; d%26lt;=day)
cout%26lt;%26lt;year-y;
else
cout%26lt;%26lt;(year-y-1);
getch();
}
Reply:Use excel sheet
put current date in date formatted cell
put your date of birth in another cell
get the dufference between above cells in formula assigned cell. You gaet exact no.of days.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment