#include "stdio.h"
main()
{
double a = 0.0;
double b = 0.0;
char ch = 0;
printf("请输入算式:");
scanf("%lf%c%lf", &a, &ch,&b);
switch (ch)
{
case '+':
printf("输出结果:%.2lf %c %.2lf = %.2lf",a,ch,a+b);
break;
default:
printf("输入错误,请重新输入!\n");
}
}
double a = 0.0;
double b = 0.0;
此处你已经对a,b定义并赋值了。输出当然是0.0
为何不写成double a,b;
(我也是初学……)
#include "stdio.h"
void main()
{
float a,b;
char ch ;
printf("请输入算式\n");
scanf("%f%c%f", &a, &ch,&b);
switch (ch)
{
case '+':
printf("输出结果:%.2f %c %.2f = %.2f",a,ch,b,a+b);
break;
default:
printf("输入错误,请重新输入!\n");
}
}