C语言!~!求助!~!

来源:百度知道 编辑:UC知道 时间:2024/05/07 20:39:21
main()
{
int a,b;
scanf("%d%d",&a,&b);
switch(a+b)
{
case 1:printf("*\n");
case 2:printf("**\n");
}
}

F:\工具\Microsoft Visual C++ 6.0 简体中文企业版0\文件\hao\hao1.c(5) : warning C4013: 'scanf' undefined; assuming extern returning int
F:\工具\Microsoft Visual C++ 6.0 简体中文企业版0\文件\hao\hao1.c(7) : error C2050: switch expression not integral
F:\工具\Microsoft Visual C++ 6.0 简体中文企业版0\文件\hao\hao1.c(8) : error C2052: 'const double ' : illegal type for case expression
F:\工具\Microsoft Visual C++ 6.0 简体中文企业版0\文件\hao\hao1.c(8) : warning C4013: 'printf' undefined; assuming extern returning int
F:\工具\Microsoft Visual C++ 6.0 简体中文企业版0\文件\hao\hao1.c(9) : error C2052: 'const double ' : illegal type for case expression
执行 cl.exe 时出错.

hao1.exe - 1 erro

包含头文件:#include<stdio.h>
你可以写成这样:
#include<stdio.h>
main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
switch(c)
{
case 1:printf("*\n");break;
case 2:printf("**\n");
}
}

加上#include<stdio.h>头文件

要加头文件
#include <stdio.h>
我加头文件以后在Unix下编译成功,
还有可能你的环境不能支持switch(a+b)吧,如果不行就换成c=a+b;switch(c)
不知道你想实现什么,如果你想实现a+b=1,case 1而已的话就在后面加break;
如果不是的话算我没说