写法一:
int main()
{
int year, month, day, count_all;
int count1 = 0;
int count2 = 0;
int count3 = 0;
printf("请输入时间\n");
scanf("%d%d%d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
int i =1;
for (i; i < month + 1; i++) {
switch (i) {
case 1||3||5||7||8||10||12:
count1++; break;
case 4||6||9||11:
count1++; break;
case 2:
count3++; break;
}
}
if ((year / 4 == 0 && year / 100 != 0) || year / 400 == 0) {
count_all=count1 * 31 + count2 * 30 + count3 * 2+day;
}
else {
count_all= count1 * 31 + count2 * 30 + count3 * 28+day;
}
printf("%d", count_all);
return 0;
}出现如下问题:
原因(个人):运行之前将该带有逻辑或的运算符默认为1(可能是为契合case后为常量),所以那两行实际为两个case 1
改法:将case分开写,或者用if代替switch语句