c program calculate tomorrow's date.
c program calculate tomorrow's date.
include <stdio.h>
#include <conio.h>
struct date
{
int day;
int month;
int year;
} today, tomorrow;
int main()
{
char again;
again:
struct date;
printf("Enter today's date: ");
scanf("%d", &today.day);
printf("Enter month: ");
scanf("%d", &today.month);
printf("Enter year: ");
scanf("%d", &today.year);
switch(today.month)
{
case 1:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/%d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/%d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 2:
if(today.day==28)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<28 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 3:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 4:
if(today.day==30)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<30 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 5:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 6:
if(today.day==30)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<30 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 7:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 8:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 9:
if(today.day==30)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<30 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 10:
if(today.day==31)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 11:
if(today.day==30)
{
tomorrow.month=today.month+1;
tomorrow.day=1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else if(today.day<30 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
case 12:
if(today.day==31)
{
tomorrow.month=1;
tomorrow.day=1;
tomorrow.year=today.year+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, tomorrow.year);
}
else if(today.day<31 && today.day>=1)
{
tomorrow.month=today.month;
tomorrow.day=today.day+1;
printf("Todays date is: %02d/%02d/%4d\n", today.day, today.month, today.year);
printf("Tomorrow date will
be: %02d/%02d/d", tomorrow.day, tomorrow.month, today.year);
}
else
printf("Enter a valid date, month and year");
break;
default:
printf("Enter a valid date, month and year");
}
printf("\nWould you like to input again? y/n ");
again=getche();
printf("\n");
if(again=='y' || again=='Y')
{
goto again;
}
getch();
}