#include "stdio.h"
void main()
{
float a,b,c;
char ch,ch1;
printf("请输入表达式如 5+6= 然后按回车键:");
scanf("%f%c%f%c",&a,&ch,&b,&ch1);
switch(ch)
{
case '+':
c=a+b;
printf("%f+%f=%f\n",a,b,c);
break;
case '-':
c=a-b;
printf("%f-%f=%f\n",a,b,c);
break;
case '*':
c=a*b;
printf("%f*%f=%f\n",a,b,c);
break;
case '/':
switch(b==0)
{
case 1:
printf("输入有误,请重试:"); break;
case 0:
c=a/b;
printf("%f/%f=%f\n",a,b,c);
break;
}break;
default:
printf("输入表达式错误或该计算器不具备 %ch 功能\n",ch);
}
}
这个程序试过了,完全能用,请给个满分哦
#include
main()
{
double a,b,w,x,y,z;
char ch;
while(scanf("%lf %c %lf",&a,&ch,&b)!=1)
{
if(ch=='*')
{w=a*b;printf("%lf*%lf=%lf\n",a,b,w);}
if(ch=='/')
{
if(b==0)printf("输入有误\n");
else {x=a/b;printf("%lf/%lf=%lf\n",a,b,x);}
}
if(ch=='+')
{y=a+b;printf("%lf+%lf=%lf\n",a,b,y);}
if(ch=='-')
{z=a-b;printf("%lf-%lf=%lf\n",a,b,z);}
}
}
# include
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<cout<
}
参考http://zhidao.baidu.com/question/534821773?&oldq=1,不知道是否是你想要的。