新手写了个计算器求指教!!!
#include <stdio.h>int main()
{
int op1, op2;
char ch;
float result;
while(1)
{
printf("请输入要计算的式子:");
scanf("%d%c%d",&op1,&ch,&op2);
switch(ch)
{
case '-' : result =op1 - op2;
break;
case '+': result =op1 + op2;
break;
case '*': result = op1 * op2;
break;
case '%':result = op1 % op2;
break;
case '/':
if(op2 !=0)
{
result =(float)op1 / op2;
break;
}
else
{
printf("除数不能为零!\n");
break;
}
}
printf("结果是:%.2f\n",result);
}
return 0;
}
页:
[1]