- 论坛徽章:
- 0
|
#include<iostream.h>;
void play()
{int d=0,zhou,year,y,month,day,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
loop:cout<<"请输入年月日(1900/1/1~?)\n";
cin>;>;year;
cout<<"年"<<endl;
cin>;>;month;
cout<<"月"<<endl;
cin>;>;day;
cout<<"日"<<endl;
if(month>;12){cout<<"一年几个月呀?请重新输入"<<endl;goto loop;}
if((year%4==0&&year%100!=0)||(year%400==0))
{if((month==2)&&(day>;=30)){cout<<"您输入的年份是闰年,2月只有29天,请重新输入\n";goto loop;}
else if(((month==1)||(month==3)||(month==5)||(month==7)||(month== ||(month==10)||(month==12))&&(day>;31))
{cout<<"您输入的月份只有31天,请重新输入\n";goto loop;}
else if(((month==4)||(month==6)||(month==9)||(month==11))&&(day>;30))
{cout<<"您输入的月份只有30天,请重新输入\n";goto loop;}}
else {if((month==2)&&(day>;2 ){cout<<"您输入的年份2月只有28天,请重新输入\n";goto loop;}
else if(((month==1)||(month==3)||(month==5)||(month==7)||(month== ||(month==10)||(month==12))&&(day>;31))
{cout<<"您输入的月份只有31天,请重新输入\n";goto loop;}
else if(((month==4)||(month==6)||(month==9)||(month==11))&&(day>;30))
{cout<<"您输入的月份只有30天,请重新输入\n";goto loop;}}
for(y=1900;y<year;y++)
if((y%4==0&&y%100!=0)||(y%400==0))
d+=366;
else d+=365;
for(int i=1;i<month;i++)
d+=a;
if((month>;2)&&((y%4==0&&y%100!=0)||(y%400==0)))
d+=1;
d+=day;
zhou=d%7;
cout<<"这一天是:";
switch(zhou)
{case 1:cout<<"周一"<<endl;break;
case 2:cout<<"周二"<<endl;break;
case 3:cout<<"周三"<<endl;break;
case 4:cout<<"周四"<<endl;break;
case 5:cout<<"周五"<<endl;break;
case 6:cout<<"周六"<<endl;break;
default:cout<<"周日"<<endl;break;
}}
void out()
{char q;char p;
cout<<"是否进行星期查询(y/n)"<<endl;
cin>;>;q;
if(q=='y')
{play();
for(int x=1;x<=100;x++)
{cout<<"是否继续(y/n)";
cin>;>;p;
if(p=='y')play();
else if(p=='n'){ cout<<"感谢使用,再见!";break;}}}
else cout<<"欢迎下次使用!再见。"<<endl;
}
void main()
{out();
}
这是我编的一个查询星期几的程序,请各位高手指教!谢谢! |
|