#include<stdio.h>
void menu()//菜单函数
{
printf("************************************\n");
printf("***** 1.add 2.sub *****\n");
printf("***** 3.mul 4.div *****\n");
printf("*********** 0.exit ***********\n");
printf("************************************\n");
}
double Add(double x, double y)//加法函数
{
return x + y;
}
double Sub(double x, double y)//减法函数
{
return x - y;
}
double Mul(double x, double y)//乘法函数
{
return x * y;
}
double Div(double x, double y)//除法函数
{
return x / y;
}
int main()
{
int input = 0;//运算符
double x = 0.0;//第一个运算数
double y = 0.0;//第二个运算数
do
{
menu();
printf("请选择:>");
scanf("%d", &input);
if (input >= 1 && input <= 4)
{
printf("请输入两个操作数(用空格分隔):>");
scanf("%lf%lf", &x, &y);
}
switch (input)
{
case 1:
printf("%lf\n", Add(x, y));
break;
case 2:
printf("%lf\n", Sub(x, y));
break;
case 3:
printf("%lf\n", Mul(x, y));
break;
case 4:
printf("%lf\n", Div(x, y));
break;
case 0:
printf("退出\n");
break;
default:
printf("输入错误,请重新输入\n");
break;
}
} while (input);
return 0;
}