Input Name and Date of Birth from the user and display name with age. The age should be displayed as number of years.
1
Expert's answer
2012-10-08T10:48:35-0400
#include<time.h> #include<iostream.h>
char name[30]; int& y, m, d; double T, a, b;
void main(){ cout<<"Enter the name: "; cin>>name; cout<<"Enter the year of birth (1970-2012): "; cin>>y; cout<<"Enter the month of birth (1-12): "; cin>>m; cout<<"Enter the day of birth (0-31): "; cin>>d; T = time(NULL); a = d; for (int i=1; i<m; i++){ & a += 30; & if (i%2!=0) a += 1; } for (i=1970; i<y; i++){ & a += 365; & if (i%4==0) a += 1; } a = a*24*3600; int b=0; while (a<=T){ & a += 365*24*3600; & if (y%4==0) a+= 24*3600; & if (a<=T) b++; & y++; } cout<<"The age of "<<name<<" is "<<b<<" years.\n"; }
Comments
Leave a comment