这个case语句怎么回事啊啊啊啊啊啊啊啊啊啊!!!!
#include <stdio.h>#define a1 "一马当先"
#define a2 "二龙腾飞"
#define a3 "三阳开泰"
#define a4 "四季平安"
#define a5 "五福临门"
#define a6 "六六大顺"
#define a7 "七星高照"
#define a8 "八面来风"
#define a9 "九九归一"
#define a10 "十全十美"
int main(void)
{
int num;
printf("请输入1 - 10 之间的任意一个数: \n");
while(scanf("%d",&num)==1)
{
switch(num);
{
case '1':
printf("%d\n", 1);
break;
case '2':
printf("%d\n", 2);
break;
case '3':
printf("%d\n", 3);
break;
case '4':
printf("%d\n", 4);
break;
case '5':
printf("%d\n", 5);
break;
case '6':
printf("%d\n", 6);
break;
case '7':
printf("%d\n", 7);
break;
case '8':
printf("%d\n", 8);
break;
case '9':
pritnf("%d\n", 9);
break;
}
}
getchar();
getchar();
return(0);
}
有一个报错消息,怎么回事啊啊啊啊啊啊!!!
报错消息是 “illegal case”
case 后可以是字符也可以是数字看你前面定义的是char 还是int
scanf("%d",&num)返回的是正确赋值给变量的个数,==1可以不用,因为每次你输入一个数就会成功赋值给变量num,scanf的返回值永远是1,当你输入一个并不是数字的数时,比如a,就会跳出while循环
define 定义的时字符打印时应该以%s的形式打印 switch(num);
这个后面不能有分号
第48行的printf打错了! #include <stdio.h>
#define a1 "一马当先"
#define a2 "二龙腾飞"
#define a3 "三阳开泰"
#define a4 "四季平安"
#define a5 "五福临门"
#define a6 "六六大顺"
#define a7 "七星高照"
#define a8 "八面来风"
#define a9 "九九归一"
#define a10 "十全十美"
int main(void)
{
int num;
printf("请输入1 - 10 之间的任意一个数: \n");
scanf("%d", &num);
switch(num)
{
case '1':
printf("%d\n", num);
break;
case '2':
printf("%d\n", num);
break;
case '3':
printf("%d\n", num);
break;
case '4':
printf("%d\n", num);
break;
case '5':
printf("%d\n", num);
break;
case '6':
printf("%d\n", num);
break;
case '7':
printf("%d\n", num);
break;
case '8':
printf("%d\n", num);
break;
case '9':
printf("%d\n", num);
break;
}
return(0);
} switch 后面不该有分号。 另有一处printf拼写错误一起加油 貌似跳不出while(scanf("%d",&num)==1)循环 本帖最后由 风雪幻林 于 2014-4-19 22:31 编辑
#include <stdio.h>
#define a1 "一马当先"
#define a2 "二龙腾飞"
#define a3 "三阳开泰"
#define a4 "四季平安"
#define a5 "五福临门"
#define a6 "六六大顺"
#define a7 "七星高照"
#define a8 "八面来风"
#define a9 "九九归一"
#define a10 "十全十美"
void main()
{
int num;
printf("请输入1 - 10 之间的任意一个数: \n");
scanf("%d",&num);
{
switch(num)
{
case 1:
printf("%s\n", a1);
break;
case 2:
printf("%s\n", a2);
break;
case 3:
printf("%s\n", a3);
break;
case 4:
printf("%s\n", a4);
break;
case 5:
printf("%s\n", a5);
break;
case 6:
printf("%s\n", a6);
break;
case 7:
printf("%s\n", a7);
break;
case 8:
printf("%s\n", a8);
break;
case 9:
printf("%s\n", a9);
break;
}
}
return(0);
}
case 不能用“单引号” 你这代码....... 错误真心不少 我随便改了下大概可以运行起来了#include <stdio.h>
#define a1 "一马当先"
#define a2 "二龙腾飞"
#define a3 "三阳开泰"
#define a4 "四季平安"
#define a5 "五福临门"
#define a6 "六六大顺"
#define a7 "七星高照"
#define a8 "八面来风"
#define a9 "九九归一"
#define a10 "十全十美"
void cls();
int main(void)
{
char num;
s: printf("请输入1 - 10 之间的任意一个数: \n");
num = getchar();
switch(num)
{
case '1':
printf("%s\n", a1);
cls();
goto s;
case '2':
printf("%s\n", a2);
cls();
goto s;
case '3':
printf("%s\n", a3);
cls();
goto s;
case '4':
printf("%s\n", a4);
cls();
goto s;
case '5':
printf("%s\n", a5);
cls();
goto s;
case '6':
printf("%s\n", a6);
cls();
goto s;
case '7':
printf("%s\n", a7);
cls();
goto s;
case '8':
printf("%s\n", a8);
cls();
goto s;
case '9':
printf("%s\n", a9);
cls();
goto s;
default:
printf("你的输入有误!\n");
cls();
goto s;
}
return 0;
}
void cls()
{
char ch;
while((ch = getchar())!='\n');
} #include <stdio.h>
#define a1 "一马当先"
#define a2 "二龙腾飞"
#define a3 "三阳开泰"
#define a4 "四季平安"
#define a5 "五福临门"
#define a6 "六六大顺"
#define a7 "七星高照"
#define a8 "八面来风"
#define a9 "九九归一"
#define a10 "十全十美"
int main(void)
{
int num;
printf("请输入1 - 10 之间的任意一个数: \n");
scanf("%d",&num);
switch(num)
{
case 1:
printf(a1);
break;
case 2:
printf(a2);
break;
case 3:
printf(a3);
break;
case 4:
printf(a4);
break;
case 5:
printf(a5);
break;
case 6:
printf(a6);
break;
case 7:
printf(a7);
break;
case 8:
printf(a8);
break;
case 9:
printf(a9);
break;
}
getchar();
return(0);
}
不知道这是你要的么 printf打错了!你编译 看看 提示啊
页:
[1]