下为一计算器程序 存在一问题 即无法实现第二次连加或连减,连乘和连除可以。求解。。
#include<stdio.h>
int main()
{
float a,c,e,result;
char b,d;
scanf("%f%c%f",&a,&b,&c);
result=a;
while(b!='#')
{
switch(b)
{
case '+':result=result+c;break;
case '-':result=result-c;break;
case '*':result=result*c;break;
case '/':result=result/c;break;
}
printf("the result is %f\n",result);
scanf("%c%f",&d,&e);
b=d;
c=e;
}
printf("the reult is %f\n",result);
return 0;
}
[解决办法]
#include <stdio.h>#include <stdlib.h>int main(){ float a,c,e,result; char b,d; scanf("%f%c%f",&a,&b,&c); fflush(stdin); result=a; while(b!='#') { switch(b) { case '+':result=result+c;break; case '-':result=result-c;break; case '*':result=result*c;break; case '/':result=result/c;break; } printf("the result is %f\n",result); scanf("%c%f",&d,&e); fflush(stdin); b=d; c=e; } printf("the reult is %f\n",result); system("pause"); return 0;}