Ex2_10.cpp
上传用户:wuzhousb
上传日期:2022-07-12
资源大小:380k
文件大小:1k
- //【例2.10】设计一个计算器程序,实现加、减、乘、除运算。
- #include <iostream>
- using namespace std;
- int main(){
- float num1,num2;
- char op;
- cout<<"输入操作数1,运算符,操作数2:"<<endl;
- cin>>num1>>op>>num2;
- switch(op){
- case '+': cout<<num1<<op<<num2<<"="<<num1+num2<<endl; break;
- case '-': cout<<num1<<op<<num2<<"="<<num1-num2<<endl; break;
- case '*': cout<<num1<<op<<num2<<"="<<num1*num2<<endl; break;
- case '/': cout<<num1<<op<<num2<<"="<<num1/num2<<endl; break;
- default : cout<<op<<"是无效运算符!";
- }
- return 0;
- }