帮我看看这个switch的问题,简单算法,老是error
#include<stdio.h>voidmain(void){floatx,y;charch;printf("Pleaseinputx,yandcharcter.\n"...
#include<stdio.h>
void main(void)
{
float x,y;
char ch;
printf("Please input x, y and charcter.\n");
scanf("%f,%c,%f",&x,&ch,&y);
switch (ch)
{
case '+':printf("%f+%f=%f\n",x,y,x+y);break;
case '-':printf("%f-%f=%f\n",x,y,x-y);break;
case '*':printf("%f*%f=%f\n",x,y,x*y);break;
case '/':
if (y!=0.0)
printf("%f/%f=%f\n",x,y,x/y);
else
printf("error!\n");break;
default:
printf("error!\n");break;
}
} 展开
void main(void)
{
float x,y;
char ch;
printf("Please input x, y and charcter.\n");
scanf("%f,%c,%f",&x,&ch,&y);
switch (ch)
{
case '+':printf("%f+%f=%f\n",x,y,x+y);break;
case '-':printf("%f-%f=%f\n",x,y,x-y);break;
case '*':printf("%f*%f=%f\n",x,y,x*y);break;
case '/':
if (y!=0.0)
printf("%f/%f=%f\n",x,y,x/y);
else
printf("error!\n");break;
default:
printf("error!\n");break;
}
} 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询