编写一个菜单程序输入1~5进入相应选择项假设相应选择为1加法运算2减法运算3乘法运算4除法运算和5退出

2024-11-07 23:59:49
推荐回答(2个)
回答1:

已调试通过!不知满足你的需求不?
4种运算的函数未给出!我想很简单,应该可以补充完成吧!
自己多动手,收获不小的!!!
#include
#include
#include
void main()
{
char c;

while(1)
{
printf(" 1.add\n");
printf(" 2.sub\n");
printf(" 3.mul\n");
printf(" 4.div\n");
printf("select:");
cin>>c;
switch(c)
{
case '1':
printf("1.add\n");
//add();
break;
case '2':
printf("2.sub\n");
//sub();
break;
case '3':
printf("3.mul\n");
//mul();
break;
case '4':
printf("4.div\n");
//div();
break;
case '5':
printf("5.exit\n");
exit(0);
break;
default:
printf("input error!\n");
break;
}
}
}

回答2:

#include
using namespace std;
int jia()
{
int x,y;
cout<<"输入:"< cin>>x>>y;
return x+y;
}
int jian()
{
int x,y;
cout<<"输入:"< cin>>x>>y;
return x-y;
}
int cheng()
{
int x,y;
cout<<"输入:"< cin>>x>>y;
return x*y;
}
int chu()
{
int x,y;
cout<<"输入:"< cin>>x>>y;
return x/y;
}

void Menu()
{
cout<<"1,加法"< cout<<"2,减法"< cout<<"3,乘法"< cout<<"4,除法"< cout<<"5,退出"<}
int main()
{
int Quit=1;
int a,b;
int Sel;
while(Quit!=0)
{
cout< Menu();
cin>>Sel;
switch(Sel)
{
case 1: cout<<"结果"< case 2: cout<<"结果"< case 3: cout<<"结果"< case 4: cout<<"结果"< case 5:Quit=0;break;
default:printf("选择错误,请重新选择\n");
}

}
}
//数据类型自己改吧~