这里所说的计算器,是仅可以进行加减乘除基本简单运算的计算器,并不是复杂运算的计算器。
插入代码:
#include <stdio.h>
#include <Windows.h>
#pragma warning(disable:4996)
//计算器
int my_add(int x, int y)//加法运算
{
return x + y;
}
int my_sub(int x, int y)//减法运算
{
return x - y;
}
int my_mul(int x, int y)//乘法运算
{
return x*y;
}
int my_div(int x, int y)//除法运算
{
if (y == 0){ //分母为零
printf("div zero!error!");
return 0;
}
return x / y;
}
void menu() //主页面
{
printf("#############################\n");
printf("### 1.add 2.sub ###\n");
printf("### 3.mul 4.div ###\n");
printf("### 0.quit ###\n");
printf("Please select!\n");
}
int main()
{
int select = 0;
int x, y;
int ret = 0;
do{
menu();
scanf("%d", &select);
if (select >=