#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
	int gd=DETECT,gm,year,month,day,cy,cm,cd,i,j,maxx,maxy;
	int y,m,d;
	int midx, midy;
	int stangle = 0, endangle = 360;
	int xradius = 100, yradius = 50,xradius1 = 2, yradius1 = 2;
	int radius = 50;
	clrscr();
	initgraph(&gd,&gm,"d:\\tc\\bgi");
	maxx=getmaxx();
	maxy=getmaxy();
	for(i=0;i<10;i++)
	{
	setcolor(4);
		rectangle(i,i,maxx-i,maxy-i);
		rectangle(9,11+i,629,45-i);
	}
	for(i=0;i<315;i++)
	{
	delay(3);
	setcolor(2);
		rectangle(10+i,21,630-i,35);
		setcolor(i);
		outtextxy(280,24,"AGE CALCULATOR");
		setcolor(14);
		outtextxy(28,70,"*#### WELCOME ####*");
	}
	midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor());

   /* draw ellipse */
   for(i=1;i<=100;i+=5)
   {
		delay(30);
		setcolor(2);
		ellipse(midx+i, midy+i, stangle, endangle,
		   xradius, yradius);
		setcolor(4);
		ellipse(midx-i, midy+i, stangle, endangle,
		   xradius, yradius);
		setcolor(6);
		ellipse(midx+i, midy-i, stangle, endangle,
		   xradius, yradius);
		setcolor(5);
		ellipse(midx-i, midy-i, stangle, endangle,
		   xradius, yradius);
   }


   for(i=5;i<=100;i+=3)
   {

		setcolor(15);
		circle(midx+i, midy-i, radius);
		setcolor(11);
		circle(midx+i, midy+i, radius);
		setcolor(3);
		circle(midx-i, midy-i, radius);
		setcolor(14);
		circle(midx-i, midy+i, radius);
		setcolor(12+i);
		//outtextxy(midx+200,midy,"PARITOSH");
		delay(20);
   }
   for(i=1;i<=100;i+=5)
   {
		delay(10);
		setcolor(15);
		ellipse(midx+i, midy, stangle, endangle,
		   xradius1+i, yradius1+i);
		setcolor(11);
		ellipse(midx, midy+i, stangle, endangle,
		   xradius1+i, yradius1+i);
		setcolor(3);
		ellipse(midx, midy-i, stangle, endangle,
		   xradius1+i, yradius1+i);
		setcolor(14);
		ellipse(midx-i, midy, stangle, endangle,
		   xradius1+i, yradius1+i);
		   //outtextxy(midx-20,midy,"WELCOME");
   }
   setcolor(14);
		   outtextxy(350,440,"* PRESS ANY KEY TO CONTINUE....");

	getch();
	closegraph();
	//gotoxy(300,200);
	//for(i=0;i<300;i++);
	//printf("%c",l);
 ll:	printf("\t\t\t\t\t :DATE  FORMAT:\n");
	printf("\t\t\t\t\tYYYY MM DD\n");

	printf("\n* ENTER THE CURRENT DATE:\t\t");
	scanf("%d%d%d",&cy,&cm,&cd);
	printf("\n* ENTER YOUR DATE OF BIRTH:\t\t");
	scanf("%d%d%d",&year,&month,&day);
	if(cm<=12 && month<=12 && cd<=31 && day<=31)
	{
		if(cd>=day)
			d=cd-day;
		else
		{
			d=(cd+30)-day;
			month=month+1;
		}
		if(cm>=month)
			m=cm-month;
		else
		{
			m=(cm+12)-month;
			year=year+1;
		}
		if(cy>=year)
			y=cy-year;
		else
		{
		mm:	printf("\nYOU HAVEN'T INPUT ACCURATELY !....\n");
			printf("PLEASE, INPUT AGAIN....\n\n");
			goto ll;
		}
		printf("\n* YOUR AGE ON THE CURRENT DATE:\t\t%d   %d  %d",y,m,d);
		printf("\n\n\n\n\n\n* PRESS ANY KEY TO EXIT....");
	}
	else
		goto mm;
	getch();
}

Dani AI

Generated

Good attempt, . As asked, formatting helps; as and noted, the program relies on Turbo‑C-only headers (conio.h, graphics.h, dos.h) and uses nonportable calls. There are a few functional bugs to fix: the borrow logic changes the birth fields instead of the current ones (e.g., month = month + 1 and year = year + 1 in the posted code are wrong), every month is treated as 30 days, and there’s no robust validation (month/day ranges, leap years, or DOB-after-current-date). Also use int main(void) and avoid goto for clarity.

Correct approach (high level):

  • Validate both dates: month in 1..12 and day ≤ days_in_month(month, year) (handle Feb leap years).
  • Get current date from the system (time.h) or accept a well-validated current-date input.
  • Compute years = cy - by, months = cm - bm, days = cd - bd.
  • If days < 0, borrow one month from months and add the actual number of days in the previous calendar month (not a constant 30).
  • If months < 0, decrement years and add 12 to months.
  • Reject a DOB that is strictly later than the current date.

A compact, portable example (replace system-date input with user input if you prefer):

#include <stdio.h>
#include <time.h>

static int is_leap(int y){ return (y%4==0 && (y%100!=0 || y%400==0)); }
static int days_in_month(int m,int y){
    if(m==2) return is_leap(y)?29:28;
    if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) return 31;
    return 30;
}

int main(void){
    int by,bm,bd;
    time_t t = time(NULL);
    struct tm *now = localtime(&t);
    int cy = now->tm_year+1900, cm = now->tm_mon+1, cd = now->tm_mday;

    printf("Today: %04d-%02d-%02d\nEnter DOB (YYYY MM DD): ", cy, cm, cd);
    if(scanf("%d %d %d",&by,&bm,&bd)!=3) return 1;
    if(bm<1||bm>12||bd<1||bd>days_in_month(bm,by)){ fprintf(stderr,"Invalid DOB\n"); return 1; }
    if(by>cy || (by==cy && (bm>cm || (bm==cm && bd>cd)))){ fprintf(stderr,"DOB in future\n"); return 1; }

    int y = cy - by, m = cm - bm, d = cd - bd;
    if(d < 0){
        int pm = (cm==1)?12:cm-1;
        int py = (cm==1)?cy-1:cy;
        d += days_in_month(pm, py);
        m -= 1;
    }
    if(m < 0){ m += 12; y -= 1; }
    printf("Age: %d years, %d months, %d days\n", y, m, d);
    return 0;
}

Troubleshooting tips: test edge cases (DOB on Feb 29, end-of-month boundaries), compile with gcc -std=c11 -Wall -Wextra, and avoid mixing Turbo‑C graphics calls with modern compilers.

Recommended Answers

All 3 Replies

First your code is not formatted. Explain yourself. How does it failed?

#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()

I'm assuming those three headers provide all the undeclared identifiers in your code. Care to share with us where they come from?

main() returns int.

Care to share with us where they come from?

They are Turbo C headers (and/or non-standard ones). It was considered a nice compiler back in 1992.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.