WHAT'S NEW?
Loading...

Code for printing tomorrow's date using structure





//With this example let's see how to make and use a structure


#include<iostream.h>

struct date
{
  int day,  month,  year;
}t1, t2;  //t1=>today's date t2=>tomorrow's date

void main()
{
    int i, days[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

cout<<"Enter today's date ";
cin>>t1.day>>t1.month>>t1.year;

for(i=0;i<12;++i)
{
    if(i+1==t1.month)
    {
       if(t1.day<days[i])
       {
           t2.day=t1 .day+1;
           t2.month=t1.month;
           t2.year=t1.year;
       }
        else if(t1 .day==days[i])
       {
            t2.month=t1.month+1;
            t2.day=1;
            if(t1.month==12)
           {
                t2.year=t1.year+1;
           }
           else
                t2.year=t1.year;
       }
   }
}

cout<<"\n\n tomorrow's date: "<<t2.day<<t2.month<<t2 .year;
}


0 comments:

Post a Comment