满意答案
jsoulj573
2014.05.17
采纳率:57% 等级:8
已帮助:1013人
#include
void main()
{
char operator0=0;
int operand1=0, res=0;
printf("计算器运算如下:");
for(; ; )
{
scanf("%d", &operand1);//输入第一个数,并赋值给总和
res=operand1;
while(operator0!='=')
{
scanf("%c",&operator0);
if(operator0=='=')break;//如果输入'=',马上终止循环
scanf("%d",&operand1);
if(operator0=='+')
{
res=res+operand1;
}
else if(operator0=='-')
{
res=res-operand1;
}
else if(operator0=='*')
{
res=res*operand1;
}
else if(operator0=='/')
{
res=res/operand1;
}
}
printf("%d\n", res);
break;
}
}
/*简化了一下,不知道这样可不可以
getchar()可以获取一系列字符,但换行后只读取第一个
operator是C++中关键字,不能使用吧
循环中if和else if一起使用要好点吧,
求采纳!
*/
07分享举报