头秃了找不到哪里错了TAT
#include<stdio.h>int main()
{
int week;
printf("输入星期:");
scanf("%d",&week);
switch(week)
{ case 0:
if(week<1||week>7)
printf("Error!");
break;
case 1:
printf("这是星期%d\n",week);
break;
case 2:
printf("这是星期%d\n",week);
break;
case 3:
printf("这是星期%d\n",week);
break;
case 4:
printf("这是星期%d\n",week);
break;
case 5:
printf("这是星期%d\n",week);
break;
case 6:
printf("这是星期%d\n",week);
break;
case 7:
printf("这是星期%d\n",week);
break;
}
} 你想问什么?
只看到这里逻辑有问题 。
case 0:
if(week<1||week>7)
printf("Error!");
break; 你应该是想改成这样吧,输入的不是星期就是error,但是不能用case 0,这样它只有输入0才报错,输入-1什么的都不会有反应。default就是默认情况。
#include<stdio.h>
int main()
{
int week;
printf("输入星期:");
scanf("%d",&week);
switch(week)
{
case 1:
printf("这是星期%d\n",week);
break;
case 2:
printf("这是星期%d\n",week);
break;
case 3:
printf("这是星期%d\n",week);
break;
case 4:
printf("这是星期%d\n",week);
break;
case 5:
printf("这是星期%d\n",week);
break;
case 6:
printf("这是星期%d\n",week);
break;
case 7:
printf("这是星期%d\n",week);
break;
default:
printf("Error!");
break;
}
}
页:
[1]