1个回答
展开全部
C++可以吗
#include <iostream>
using namespace std;
double jia(double a,double b)
{
double c;
c=a+b;
return c;
}
double jian(double a,double b)
{
double c;
c=a-b;
return c;
}
double cheng(double a,double b)
{
double c;
c=a*b;
return c;
}
double chu(double a,double b)
{
double c;
if (b!=0)
{
c=a/b;
return c;
}
}
void main()
{
double x,y;
char ch;
cout<<"*****欢迎使用*****\n";
do
{
cout<<"\n";
cout<<"如果您要退出请输入 # 键\n";
cout<<"请输入表达式:";
cin>>x>>ch>>y;
cout<<"\n";
switch(ch)
{
case '+': cout<<x<<"+"<<y<<"="<<jia(x,y)<<"\n"; break;
case '-': cout<<x<<"-"<<y<<"="<<jian(x,y)<<"\n"; break;
case '*': cout<<x<<"*"<<y<<"="<<cheng(x,y)<<"\n"; break;
case '/': if(y!=0) cout<<x<<"/"<<y<<"="<<chu(x,y)<<"\n";else if(0==y) cout<<"您输入的有误,分母不能为0 \n"; break;
}
}while((ch=getchar())!='#');
cout<<"谢谢使用\n";
}
#include <iostream>
using namespace std;
double jia(double a,double b)
{
double c;
c=a+b;
return c;
}
double jian(double a,double b)
{
double c;
c=a-b;
return c;
}
double cheng(double a,double b)
{
double c;
c=a*b;
return c;
}
double chu(double a,double b)
{
double c;
if (b!=0)
{
c=a/b;
return c;
}
}
void main()
{
double x,y;
char ch;
cout<<"*****欢迎使用*****\n";
do
{
cout<<"\n";
cout<<"如果您要退出请输入 # 键\n";
cout<<"请输入表达式:";
cin>>x>>ch>>y;
cout<<"\n";
switch(ch)
{
case '+': cout<<x<<"+"<<y<<"="<<jia(x,y)<<"\n"; break;
case '-': cout<<x<<"-"<<y<<"="<<jian(x,y)<<"\n"; break;
case '*': cout<<x<<"*"<<y<<"="<<cheng(x,y)<<"\n"; break;
case '/': if(y!=0) cout<<x<<"/"<<y<<"="<<chu(x,y)<<"\n";else if(0==y) cout<<"您输入的有误,分母不能为0 \n"; break;
}
}while((ch=getchar())!='#');
cout<<"谢谢使用\n";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询