#include <stdio.h>
int main()
{
printf("------------------------输入年月日,计算星期几----------------------\n\n\n");
while(1)
{
const int biaozhun1=1900;
const int biaozhun2=1;
const int biaozhun3=1;
int year,month,day;
int y,m,t;
int days=0,days1=0,days2=0,days3;
printf("请输入年月日(例如2016 3 15):");
scanf("%d %d %d",&year,&month,&day);
while(year<1900)
{
printf("年份有误,请重新输入:");
scanf("%d",&year);
}
y=year;
//这个赋值原先放错了位置,放在上面了,所以后来重新输入的时候y没有被赋值,所以出现了错误!
while(month<1||month>12)
{
printf("月份有误,请重新输入:");
scanf("%d",&month);
}
while(day<1||day>31)
{
printf("日期有误,请重新输入:");
scanf("%d",&day);
}
printf("计算中,请稍后……") ;
while(y!=biaozhun1)
{
if((y-1)%4==0&&(y-1)%100!=0)
{
days1+=366;
}else
{
days1+=365;
}
y--;
}
m=month;
while(m!=biaozhun2)
{
if(m==2||m==4||m==6||m==8||m==9||m==11)
{
days2+=31;
}else if(m==5||m==7||m==10||m==12)
{
days2+=30;
}else if(m==3)
{
if(year%4==0&&year%100!=0)
{
days2+=29;
}else
{
days2+=28;
}
}
m--;
}
days3=day-1;
days=days1+days2+days3;
t=days%7;
switch(t)
{
case 0:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期一\n\n",year,month,day);break;
case 1:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期二\n\n",year,month,day);break;
case 2:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期三\n\n",year,month,day);break;
case 3:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期四\n\n",year,month,day);break;
case 4:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期五\n\n",year,month,day);break;
case 5:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期六\n\n",year,month,day);break;
case 6:printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b
\n");
printf("
%d年%d月%d日是星期日\n\n",year,month,day);break;
default:printf("运行出错!请调试后运行 !");
}
}
system ("pause");
return 0;
}
代码的问题,已经解决。。O(∩_∩)O谢谢!!!