1.写出主体main函数,以及选择语句
int main()
{
int a = 0;
int b = 0;
int chouse = 0;
int result = 0;
chouse=Menu();
if (chouse>0&&chouse<5)
{
printf("请输入两个数据:");
scanf("%d %d",&a,&b);
if (chouse==1)
{
result = MyAdd(a, b);
}
else if (chouse==2)
{
result = MySub(a, b);
}
else if (chouse==3)
{
result = MyMul(a, b);
}
else if (chouse==4)
{
result = MyDiv(a, b);
}
printf("result=%d\n",result);
}
else if(chouse==5)
{
printf("退出成功!");
}
else
{
printf("输入错误!!");
}
return 0;
}
2.制作菜单界面
int Menu()
{
printf("********************************\n");
printf("** **\n");
printf("** 1.Add 2.Sub **\n");
printf("** 3.Mul 4.Div **\n");
printf("** 5.退出 **\n");
printf("********************************\n");
int z;
printf("选择您要进行的操作:");
scanf("%d", &z);
return z;
}
3.完善选择分支需要用到的函数
int MyAdd(int a, int b)
{
int z = a + b;
return z;
}
int MySub(int a, int b)
{
int z = a - b;
return z;
}
int MyMul(int a, int b)
{
int z = a * b;
return z;
}
int MyDiv(int a, int b)
{
int z = a / b;
return z;
}