How to calculate age using C program
C Program for Age Calculation
Want to calculate age using a C program, but couldn't make the source code!!! Here I come with the program you need. I have made this one month ago, and thought to post in this blog so that you guys be helped.
Below is the C program to calculate age. Please notify me if you encounter any problem or error.
Stay tune for more updates.
THANK YOU.
Want to calculate age using a C program, but couldn't make the source code!!! Here I come with the program you need. I have made this one month ago, and thought to post in this blog so that you guys be helped.
Below is the C program to calculate age. Please notify me if you encounter any problem or error.
//This program is created by Rupam Medhi.
//You can find more program in http://computz365.blogspot.in
#include<stdio.h>
main()
{
int d1,d2,m1,m2,y1,y2,D,M,Y;
printf("Enter your Birthday-date,month,year\n");
scanf("%d%d%d",&d1,&m1,&y1);
printf("Enter today's date-date,month,year \n");
scanf("%d%d%d",&d2,&m2,&y2);
if(((d1<=d2)&&(m1<=m2))||(d1<=d2)||(m1<=m2))//default and the easy condition
{
D=d2-d1;
M=m2-m1;
Y=y2-y1;
}
if((d1>d2)&&(m1>m2))
{
D=30-d1+d2;
M=12-m1+m2-1;
Y=y2-y1-1;
}
if(d1>d2)
{
D=30-d1+d2;
M=m2-m1-1;
Y=y2-y1;
}
if((d1>d2)&&(m1==m2))
{
D=30-d1+d2;
M=12-m1+m2-1;
Y=y2-y1-1;
}
if(m1>m2)
{
D=d2-d1;
M=12-m1+m2;
Y=y2-y1-1;
}
if(y1==y2)
{
D=d2-d1;
M=m2-m1;
Y=0;
}
printf("Your age is %d years, %d months and %d days\n",Y,M,D);
}
Stay tune for more updates.
THANK YOU.
At the very end , where it's supposed to print your age it says "Variable 'D' may be uninitialized when used here" and if i run it, it begins to loop
ReplyDeleteCould you provide screenshots please? It would help me to debug and help you.
Delete