一个小计算器(可计算两位数加法,减法,乘法除法)

#include
int main()
{  double a;
double b;
double sum;


char op=0;
printf ("please input num1:\n");
scanf("%lf",&a);
getchar();


printf ("please input symbol:\n");
scanf("%c",&op);


printf ("please input num2:\n");
scanf("%lf",&b);
printf("a = %.2f,symbol = %c,b = %.2f\n",a,op,b );


if ( b == 0)
printf("input is wrong\n");
else
{



switch(op)
{
case '+':
sum = a + b;
break;




case '-':
sum = a - b;
break;


case '*':
sum = a * b;
break;


case '/':
sum = a / b;
break;


default:
printf ("input is error\n");
}


printf ("sum = %.2f\n",sum);
}
return 0;
}

你可能感兴趣的:(一个小计算器(可计算两位数加法,减法,乘法除法))