break非法终止,我想的是先用if得到a的值,然后执行break,但是程序显示非法终止,是不能这么写吗。
#include
void main()
{
int a;
double x,b,c,d,f,g,h;
printf("请输入利润:\n");
scanf("%lf",x);
b=0.1*x;
c=0.1*x+0.075*x;
d=0.1*x+0.05*x;
f=0.1*x+0.3*x;
g=0.1*x+0.015*x;
h=0.1*x+0.01*x;
if(x<=10)
a=1;
else if(1020)
a=2;
else if(2040)
a=3;
else if(4060)
a=4;
else if(60100)
a=5;
else if(1006;
switch(a)
case 1: printf("应发放奖金%.2lf",b);
break;
case 2: printf("应发放奖金%.2lf",c);
break;
case 3: printf("应发放奖金%.2lf",d);
break;
case 4: printf("应发放奖金%.2lf",f);
break;
case 5: printf("应发放奖金%.2lf",g);
break
case 6: printf("应发放奖金%.2lf",h);
}
564\545.cpp(29) : error C2043: illegal break
564\545.cpp(30) : error C2043: illegal break
564\545.cpp(31) : error C2043: illegal break
564\545.cpp(32) : error C2043: illegal break
564\545.cpp(33) : error C2043: illegal break
564\545.cpp(34) : error C2043: illegal break
564\545.cpp(35) : error C2043: illegal break
564\545.cpp(36) : error C2043: illegal break
564\545.cpp(37) : error C2043: illegal break
564\545.cpp(38) : error C2043: illegal break
564\545.cpp(39) : error C2043: illegal break
switch后边没加括号呀, scanf("%lf",x); 改成 scanf("%lf",&x);
#include <stdio.h>
int main()
{
int a;
double x,b,c,d,f,g,h;
printf("请输入利润:\n");
scanf("%lf",&x);
b=0.1*x;
c=0.1*x+0.075*x;
d=0.1*x+0.05*x;
f=0.1*x+0.3*x;
g=0.1*x+0.015*x;
h=0.1*x+0.01*x;
if(x<=10)
a=1;
else if(10<x&&x<20)
a=2;
else if(20<x&&x<40)
a=3;
else if(40<x&&x<60)
a=4;
else if(60<x&&x<100)
a=5;
else if(100<x)
a=6;
switch(a){
case 1: printf("应发放奖金%.2lf",b);break;
case 2: printf("应发放奖金%.2lf",c);
break;
case 3: printf("应发放奖金%.2lf",d);
break;
case 4: printf("应发放奖金%.2lf",f);
break;
case 5: printf("应发放奖金%.2lf",g);
break;
case 6: printf("应发放奖金%.2lf",h);
}
}
case 6,没有break
最好加一个default