C语言问题 简单计算器,编译没错误,但是计算不了
#include<math.h>#include<stdio.h>voidmain(){floatdata1,data2;charop;printf("Pleaseent...
#include <math.h>
#include <stdio.h>
void main()
{
float data1,data2;
char op;
printf("Please enter the expression:\n");
scanf("%d%c%d",&data1,&op,&data2);
switch(op)
{
case'+':
printf("%f+%f=%f\n",data1,data2,data1+data2);
break;
case'-':
printf("%f-%f=%f\n",data1,data2,data1-data2);
break;
case'*':
case'x':
case'X':
printf("%f*%f=%f\n",data1,data2,data1*data2);
break;
case'/':
if (fabs(data2) <= 1e-7)
printf("Division by zero!\n");
else
printf("%f/%f=%f\n",data1,data2,data1/data2);
break;
default:
printf("Unknown operator! \n");
}
}
就是计算什么都是0.000000+0.000000=0.000000 展开
#include <stdio.h>
void main()
{
float data1,data2;
char op;
printf("Please enter the expression:\n");
scanf("%d%c%d",&data1,&op,&data2);
switch(op)
{
case'+':
printf("%f+%f=%f\n",data1,data2,data1+data2);
break;
case'-':
printf("%f-%f=%f\n",data1,data2,data1-data2);
break;
case'*':
case'x':
case'X':
printf("%f*%f=%f\n",data1,data2,data1*data2);
break;
case'/':
if (fabs(data2) <= 1e-7)
printf("Division by zero!\n");
else
printf("%f/%f=%f\n",data1,data2,data1/data2);
break;
default:
printf("Unknown operator! \n");
}
}
就是计算什么都是0.000000+0.000000=0.000000 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询