计算器

写一个计算器   还有一些bug调试了半天  终于可以了

#include<stdio.h>

int main()
{
double a;
      double b;
double c;
      char s;


printf(" please input num1:\n");
scanf("%f",&a);
getchar();


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

printf("please input num2:\n");
  scanf("%f",&b);


print ("a = %d, s = %c,b = %d\n ",a,s,b);
switch(s)
{
case '+':
s = a + b;
break;

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

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


case '/':
{
if (b == 0)
       
    printf("error!\n");
    break;
}
        else
          {
              s = a / b;
        }
break;
        }
default:
printf("error!\n");
}
printf("%d\n",s);
return 0;  
}

猜你喜欢

转载自blog.csdn.net/weixin_42195913/article/details/80358466