c++如何编写计算器?小编代码奉上!学艺不精,请谅解!
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int a,b,c,d;
cout<<"欢迎来到计算器!本计算器能计算加减乘!你想计算加法还是减法还是乘法?(加法按1,减法按2,乘法按3)"<<endl;
cin>>c;
if(c==1){
cout<<"请输入两个数字,我会为你输出和"<<endl;
cin>>a>>b;
cout<<"正在计算中......"<<endl;
cout<<a<<"+"<<b<<"="<<e;
cout<<"竖式如下"<<endl;
cout<<" "<<a<<endl;
cout<<"+ "<<b<<endl;
cout<<"-------"<<endl;
cout<<" "<<e;
return 0;
}else if(c==2){
cout<<"请输入两个数,我会为你输出差"<<endl;
cin>>a>>b;
cout<<"第一个数大还是第二个数大?(第一个数大按1,第二个数大按2)"<<endl;
cin>>d;
if(d==2){;
cout<<"正在计算中......"<<endl;
cout<<b<<"-"<<a<<"="<<f<<endl;
cout<<"竖式如下"<<endl;
cout<<" "<<b<<endl;
cout<<"- "<<a<<endl;
cout<<"-------"<<endl;
cout<<" "<<f;
return 0;
}else if(d==1){
cout<<"正在计算中......"<<endl;
cout<<a<<"-"<<b<<"="<<a-b<<endl;
cout<<"竖式如下"<<endl;
cout<<" "<<a<<endl;
cout<<"- "<<b<<endl;
cout<<"-------"<<endl;
cout<<" "<<a-b;
return 0;
}
}else if(c==3){
cout<<"请输入两个数,我会为你输出积"<<endl;
cin>>a>>b;
cout<<"正在计算中......"<<endl;
cout<<a<<"*"<<b<<"="<<a*b<<endl;
cout<<"竖式如下"<<endl;
cout<<" "<<a<<endl;
cout<<"* "<<b<<endl;
cout<<"-------"<<endl;
cout<<" "<<a*b;
return 0;
}else{
return 0;
}
return 0;
}