switch 后面的内容要用花括号括起来。
即把case和default都括起来
另外,case后面要有空格
#include
main()
{
int i,b,number;
float a,sum;
i=1;
while(i<=5)
{
printf("周%d销售情况:\n",i);
scanf("%d",&number);
switch(number)
{
case 1:
a=2.98;
scanf("%d",&b);
sum=sum+a;
break;
case 2:
a=4.50;
scanf("%d",&b);
sum=sum+a;
break;
case 3:
a=9.98;
scanf("%d",&b);
sum=sum+a;
break;
case 4:
a=4.49;
scanf("%d",&b);
sum=sum+a;
break;
case 5:
a=6.87;
scanf("%d",&b);
sum=sum+a;
break;
default:
i++;
break;
}
}
printf("本周销售总额为:%f",sum);
return 0;
}
i++可能是出错的原因
开始初始化:number=0