⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 倒计时完善.cpp

📁 一个自己编写简单的程序
💻 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 + -