#include <stdio.h>
#include <math.h>
#include <iostream.h>
void cnt1(int m,int n);
void cnt2(int m);
void cnt3(int m);
void scan();
int daysofmonth(int m);
int year,month,day,overyear,overmonth,overday;
int cnt=0;
void main()
{
while(1)
{
int i;
scan();
if (month==overmonth)
cnt1(day,overday);
else if (month+1==overmonth)
{
cnt1(day,daysofmonth(month));
cnt3(overday);
}
else
{
cnt1(day,daysofmonth(month));
for (i=month+1;i<=overmonth-1;i++)
cnt2(i);
cnt3(overday);
}
cout<<"从"<<month<<"月"<<day<<"日"<<"到"<<overmonth<<"月"<<overday<<"日还有"<<cnt-1<<"天";
cin>>i;
break;
}
}
void scan()
{
while (1)
{
cout<<"\n";
cout<<"请输入倒计时开始日期";
/*cin>>year;*/
cin>>month;
if (month>12)
{cout<<"输入的月份是错误的,一年没有"<<month<<"月"; main();}
cin>>day;
if (day>daysofmonth(month))
{cout<<"输入的日期是错误的"<<month<<"月没有"<<day<<"号"; main();}
cout<<"请输入倒计时截止日期";
/*cin>>overyear;*/
cin>>overmonth;
if (overmonth>12)
{cout<<"输入的月份是错误的,一年没有"<<overmonth<<"月"; main();}
if (overmonth<month)
{cout<<"输入的截止日期早于开始日期,怎么倒计时?"; main();}
cin>>overday;
if (overday>daysofmonth(overmonth))
{cout<<"输入的日期是错误的"<<overmonth<<"月没有"<<overday<<"号"; main();}
if (overmonth==month && overday<day)
{cout<<"输入的截止日期早于开始日期,怎么倒计时?"; main();}
break;
}
}
void cnt1(int m,int n)
{
int i;
for (i=m;i<=n;i++)
cnt++;
}
void cnt2(int m)
{
cnt+=daysofmonth(m);
}
void cnt3(int m)
{
int i;
for (i=1;i<=m;i++)
cnt++;
}
int daysofmonth(int m)
{
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:if (((year%4==0 && year%100!=0)||year%400==0))
return 29;
else
return 28;
default: return 0;
}
}