//小型计算器C实现
#include<stdio.h>
#include<iostream>
using namespace std;
int Add(int a, int b)
{
return (a+b);
}
int Sub(int a, int b)
{
return (a-b);
}
int Mul(int a, int b)
{
return (a*b);
}
int Div(int a, int b)
{
if (b == 0)
{
printf("div zero\n");
return 0x7fffffff;
}
else
return (a/b);
}
int calcul()
{
int x=0, y=0, z=0;
char op = 0;
char ch;
do
{
printf("请输入表达式:\n");
cin>>x>>op>>y;
switch (op)
{
case '+':z = Add(x, y); break;
case '-':z = Sub(x, y); break;
case '*':z = Mul(x, y); break;
case '/':z = Div(x, y); break;
default:
printf("operator error\n");
break;
}
printf("=>%d\n",z);
printf("是否继续(n/y)\n");
getchar();
cin>>ch;
} while (ch == 'Y' || ch == 'y');
return 0;
}
int main()
{
calcul();
}