?? 倒計時完善.cpp
字號:
#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;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -