user-0 提问: 菜鸟求助！！！

回复:
user: user-1
content: 抱歉，sum应该是x

user: user-1
content: 窃以为： 以1969年12月31日（星期三）为基准， 闰年跟平年的sum应该分开算， 闰年取sum=366*（n-1）+365*（year-1970-n+1）； 平年取sum=366*n+365*(year-1970-n); 另外，switch语句部分应该改为： switch(week) {     case 0: printf("Wednesday\n");break;     case 1: printf("Thursday\n");break;     case 2: printf("Friday\n");break;     case 3: printf("Saturday\n");break;     case 4: printf("Sunday\n");break;     case 5: printf("Monday\n");break;     case 6: printf("Tuesday\n");break;  }

user: user-2
content: 1、七楼说的一样，if后面的语句缺少了{}. 2、就是year的处理出现了问题，楼主的思路没看明白，然后改了下，你看下下面代码吧。 3、在month的护理，怎么对sum再次进行了定义？而且是在{}内，根据就近原则{}内的处理只是改了这里定义的sum的值，当走出{}后，取的sum值不是你{}赋的值。 4、1970-1-1是周四吧，这个好像在代码中没有处理。。。。  代码修改后如下所示：ps:后面定义的变量名看起来很费劲 #include<stdio.h> int main() { 	int year; 	int month; 	int day; 	int week; 	int j; 	int x; 	int y; 	int z; 	int n; 	int p; 	int sum;  	printf("please enter(year=month-day):"); 	scanf("%d-%d-%d", &year, &month, &day); 	if (year<1970||year>9999) 	{ 		printf("year is error.\n"); 		return 0; 	}   	if (month>12||month<0) 	{ 		printf("month is error.\n"); 		return 0; 	}  	if (day<0) 	{ 		printf("day is error.\n"); 		return 0; 	}   	if (month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12) 	{ 		if (day>31) 		{ 			printf("day is error.\n"); 			return 0; 		} 	} 	if (month == 4||month == 6||month == 9||month == 11) 	{ 		if (day>30) 		{ 			printf("day is error.\n"); 			return 0; 		} 	}  	if ((year%4 == 0&&year%100!= 0)||year%400 == 0) 	{ 		if (month == 2) 		{ 			if (day>29) 			{ 				printf("day is error.\n"); 				return 0; 			} 		} 	} 	else 	{ 		if (month == 2) 		{ 			if (day>28) 			{ 				printf("day is error.\n"); 				return 0; 			} 		} 	} 	int i = 1970;  	int  k = 0; //	int  k = 1; //	while (i<= year) 	while (i< year) 	{ 		if ((i%4 == 0&&i%100!= 0)||i%400 == 0) 		{ 			k++; 		} 		i++; 	} 	n = k; 	x = 366*n+365*(year-1970-n); //	x = 366*n+365*(year-1970-n-1);   	sum = 0; 	if ((year%4 == 0&&year%100!= 0)||year%400 == 0) 	{ //		int sum = 0; 		int a1[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31}; 		for (i = 0; i<month; i++){ 			sum+= a1[i]; 		} 	} 	else 	{ //		int sum = 0; 		int a2[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; 		for (i = 0; i<month; i++){ 			sum+= a2[i]; 		} 	} 	y = sum; 	z = day; 	p = x+y+z+3; //	p = x+j+day; 	week = p%7; 	switch(week) 	{ 		case 0: printf("Sunday\n"); break; 		case 1: printf("Monday\n"); break; 		case 2: printf("Tuesday\n"); break; 		case 3: printf("Wednesday\n"); break; 		case 4: printf("Thursday\n"); break; 		case 5: printf("Friday\n"); break; 		case 6: printf("Saturday\n"); break; 		defult: printf("PG error\n");break; 	} 	return 0; }

user: user-1
content: 七楼好像还没有纠正算法的问题吧！？

user: user-3
content: 主要是你的那个return 0； if(day>29) printf("day is error.\n"); return 0; 应该把它修改成 if(day>29) {printf("day is error.\n"); return 0;}  不然在没有else的情况下，就容易跳出去，然后我修改了一下你的程序。 #include<stdio.h> int main() { 	int year; 	int month; 	int day; 	int week; 	long int x; 	int y; 	int z; 	int n; 	long int p; 	int sum=0; 	int i=1970; 	int  k=0;  	scanf("%d-%d-%d",&year,&month,&day);  	if(year<1970||year>9999) 	{ 		printf("year is error.\n"); 		return 0; 	}  	else 	{  		while(year>i) 		{ 			if((i%4==0&&i%100!=0)||i%400==0) 			{ 				k++; 			} 			i++; 		} 	} 	n=year-1970; 	x=366*k+365*(n-k);  	if(month>12||month<0) 	{ 		printf("month is error.\n"); 		return 0; 	} 	else 	{ 		if((year%4==0&&year%100!=0)||year%400==0) 		{ 			int a1[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; 			for(i=0;i<month;i++) 				sum+=a1[i]; 		} 		else 		{ 			int a2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 			for(i=0;i<month;i++) 				sum+=a2[i]; 		} 		y=sum; 	}  	if(day<0) 	{ 		printf("day is error.\n"); 		return 0; 	}  	else  	{ 		if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) 		{ 			if(day>31) 			{ 				printf("day is error.\n"); 				return 0; 			} 		} 		else if (month==4||month==6||month==9||month==11) 		{ 			if(day>30) 			{ 				printf("day is error.\n"); 				return 0; 			} 		} 		if((year%4==0&&year%100!=0)||year%400==0) 		{ 			if(month==2) 			{ 				if(day>29)  				{ 					printf("day is error.\n"); 					return 0; 				} 			} 		} 		else 		{ 			if(month==2) 			{ 				if(day>28)  				{ 					printf("day is error.\n"); 					return 0; 				} 			} 		}  	} 	z=day; 	p=x+y+z-4; 	week=p%7; 	switch (week) 	{ 	case 0: printf("Sunday\n");   break; 	case 1: printf("Monday\n");   break; 	case 2: printf("Tuesday\n");  break; 	case 3: printf("Wednesday\n");break; 	case 4: printf("Thursday\n"); break; 	case 5: printf("Friday\n");   break; 	case 6: printf("Saturday\n"); break; 	} 	return 0; }

user: user-4
content: 1 x=366*n+365*(year-1970-n-1); 2 p=x+j+day; 3 switch (week) {     case 0: printf("Sunday\n");   break; case 1: printf("Monday\n");   break; case 2: printf("Tuesday\n");  break; case 3: printf("Wednesday\n");break; case 4: printf("Thursday\n"); break; case 5: printf("Friday\n");   break; case 6: printf("Saturday\n"); break;      } 感觉有问题

user: user-4
content: 你应该是从1969年12月31日（星期三）为基准算起的吧！？

user: user-5
content: 引用 1 楼 ml0719787 的回复:scanf("%d-%d-%d",&year,&month,&day);这个不能这样用 scanf("%d%d%d",&year,&month,&day) 嗯。这个可以的。这个在这儿是非输入控制符，输入时需要原样输出，像3楼说的那样

user: user-6
content: 引用 1 楼 ml0719787 的回复:scanf("%d-%d-%d",&year,&month,&day);这个不能这样用 scanf("%d%d%d",&year,&month,&day) scanf("%d-%d-%d",&year,&month,&day);//可以这样用，只不过要输入2014-6-3而已。 请楼主检查scanf函数的返回值！

user: user-7
content: scanf("%d-%d-%d",&year,&month,&day);这个不能这样用 scanf("%d%d%d",&year,&month,&day)