怎样输出任意一天星期几
#include <iostream.h>int isleap(int year);
int week1(int year,int month,int day,int i);
void outputweek(int week);
int year,month,day,i;
void main()
{
cout<<"请输入年月日:";
cin>>year>>month>>day;
i=isleap(year);
static week=week1(year,month,day,i);
outputweek(week);
}
int isleap(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
return 1;
else
return 0;
}
int week1(int year,int month,int day,int i)
{
if((month>=13||day>=32)||(i=0&&month==2&&day>=29))
{
cout<<"输入错误.";
day=0;
}
switch(month)
{
case 2:if(day>=30)
{
cout<<"输入错误.";
day=0;
}
else day+=31;
break;
case 3:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29;
break;
case 4:if(day>=30)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31;
break;
case 5:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30;
break;
case 6:if(day>=30)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31;
break;
case 7:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30;
break;
case 8:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30+31;
break;
case 9:if(day>=30)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30+31+31;
break;
case 10:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30+31+31+30;
break;
case 11:if(day>=30)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30+31+31+30+31;
break;
case 12:if(day>=31)
{
cout<<"输入错误.";
day=0;
}
else day+=31+29+31+30+31+30+31+31+30+31+30;
break;
default:break;
}
if(month>=3&&i==0)
day-=1;
int week;
if(day!=0) week=(year-1)+int((year-1)*0.1*10/4)-int((year-1)*0.1*10/100)+int((year-1)*0.1*10/400)+day;
else week=0;
return week;
}
void outputweek(int week)
{
cout<<year<<"年"<<month<<"月"<<day<<"日是";
int w;
if(week!=0&&day!=0) {
w=week%7;
switch(w)
{
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;
case 0:cout<<"星期日"<<endl; break;
default:break;
}
}
}
一不是闰年能有2月29天,有的输出错误后还显示星期几。哪错啦?