Hi every one. it is my solution. if it is false, reply. using Turbo C

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
struct Date
       {
	    int y;
	    int m;
	    int d;
	    void subdates(Date, Date);
	    long int  calculate_date( Date);
	    long int setvalue(int, int , int);
	   
       };
       Date t;
void main()
{ clrscr();
    Date e,d;
    cout<<endl<<"first year: ";
    cin>>e.y;
    cout<<"first month: ";
    cin>>e.m;
    cout<<"first day: ";
    cin>>e.d;
     d.setvalue(1989,5,18);
    t.subdates(e,d);
    getch();
   }
  void Date::subdates(Date e, Date d)
  {
   long int dd, cc, diff;
   dd=calculate_date(e);
   cc=calculate_date(d);
   diff=dd-cc;

   cout<< "Zoruu: "<<diff<<endl<<dd;
  }

   long int Date::setvalue(int y1=1, int m1=1, int d1=1)
   {
    y=y1;
    m=m1;
    d=d1;
   }

   long int Date::  calculate_date(Date d)
   {long  int z=0,a=0,i;
   if(d.y==1)
   {  z=0;
     switch(d.m)
      {
       case 1: a=0; break;
       case 2: a=31; break;
       case 3: a=59; break;
       case 4: a=90; break;
       case 5: a=120; break;
       case 6: a=151; break;
       case 7: a=181; break;
       case 8: a=212; break;
       case 9: a=243; break;
       case 10: a=273; break;
       case 11: a=304; break;
       case 12: a=334; break;

      }
   }
   else  {

	      for(i=2; i<d.y; i++)
		  {

		       if(i%400==0)
			  {
				  z=z+366;
			  }
		       else{
			    if(i%100==0)
			       {
				  z=z+365;
			       }
			    else{
				 if(i%4==0)
				   {
				      z=z+366;
				   }
				 else z=z+365;
				 }
			    }
		  }
	     switch(d.m)
	     {
		      case 1: a=0; break;
		      case 2: a=31;
		      case 3: if(d.y%400==0)
				{
				 a=60;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=59;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=60;
					 }
				       else a=59;

				      }
				  }; break;
		      case 4: if(d.y%400==0)
				{
				 a=91;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=90;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=91;
					 }
				       else a=90;

				      }
				  }; break;
		      case 5:  if(d.y%400==0)
				{
				 a=121;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=120;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=121;
					 }
				       else a=120;

				      }
				  }; break;
		      case 6: if(d.y%400==0)
				{
				 a=152;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=151;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=152;
					 }
				       else a=151;

				      }
				  }; break;
		      case 7: if(d.y%400==0)
				{
				 a=182;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=181;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=182;
					 }
				       else a=181;

				      }
				  }; break;
		      case 8: if(d.y%400==0)
				{
				 a=213;
				}
			     else {
				  if(d.y%100==0)
				     {
				     a=212;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=213;
					 }
				       else a=212;

				      }
				  }; break;
		      case 9: if(d.y%400==0)
				{
				 a=244;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=243;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=244;
					 }
				       else a=243;

				      }
				  }; break;
		      case 10: if(d.y%400==0)
				{
				 a=274;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=273;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=274;
					 }
				       else a=273;

				      }
				  }; break;
		      case 11: if(d.y%400==0)
				{
				 a=305;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=304;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=305;
					 }
				       else a=304;

				      }
				  }; break;
		      case 12: if(d.y%400==0)
				{
				 a=335;
				}
			     else {
				  if(d.y%100==0)
				     {
				      a=334;
				     }
				 else {
				       if(d.y%4==0)
					 {
					   a=335;
					 }
				       else a=334;

				      }
				  }; break;
		      default: cout<<"error"<<endl;
	     }
	 }
z= z+a+d.d;
return z;
}

Recommended Answers

All 4 Replies

your solution to what exactly?

calculate to difference 2 dates.

instead of cout<< "Zoruu: "<<diff<<endl<<dd;
cout<<"difference: "<<diff;

Hi every one. it is my solution. if it is false, reply. using Turbo C

Pretty ugly, and it doesn't need to be nonstandard. Was this an assignment to do this without using the standard library?

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.