I'm trying to calculate a person's age, but I keep getting errors. What is wrong here. Thank you
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<time.h>
#include<alloc.h>
#include<math.h>
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(&tnow);
p=(char *)malloc(sizeof(tnow));
p=ctime(&tnow);
for(month=0;month<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<4;j++)
year=(year*10)+abs(48-(int)p[j+20]);
day=abs(48-(int)p[8])*10+abs(48-(int)p…
wrong:
cout<<"enter the date of birth::";
cin>>d>>ch>>m>>ch>>y;
if(!(d>=1 && d<=31 && m>=1 && m<=12)||(y%4==0 && m==2 && d>29) || (y%4!=0 && m==2 && d>28))
{
printf("You have entered wrong data\n");
goto wrong;
}
if(m<=month)
{
if(d<=day)
cout<<"The current age of you is "<<year-y;
else
cout<<"The current age of you is "<<(year-y-1);
}
else if(m>month)
cout<<"the current age of you is "<<(year-y-1);
getch();
}
I'm trying to calculate a person's age, but I keep getting errors.
Try actually reading the error messages. They usually tell you exactly what's wrong and what line the error is on.
They're not easy to understand for beginners, but learning to read and understand them is an important part of programming. If you need help understanding an error you can post it here.