C++ 在计算器中,若操作员出错,则应只询问操作员 #包括 #包括 使用名称空间std; int main(){ INTA,b; char op; op=(“+”、“-”、“/”、“*”); 库塔; 库特布; 库托普; 双结果=0.0; 如果(op=='+'){ cout

C++ 在计算器中,若操作员出错,则应只询问操作员 #包括 #包括 使用名称空间std; int main(){ INTA,b; char op; op=(“+”、“-”、“/”、“*”); 库塔; 库特布; 库托普; 双结果=0.0; 如果(op=='+'){ cout,c++,calculator,C++,Calculator,必须输入代码中与从循环中的用户接收运算符相关的部分。 循环必须继续,直到用户正确输入操作员 #include<iostream> #include<cmath> using namespace std; int main(){ int a,b; char op; op=('+','-','/','*'); cout<<"enter first number\n "; cin>>a; cout<<"

必须输入代码中与从循环中的用户接收运算符相关的部分。 循环必须继续,直到用户正确输入操作员

#include<iostream>
#include<cmath>

using namespace std;

int main(){

int a,b;
char op;
op=('+','-','/','*');


cout<<"enter first number\n ";
cin>>a;

cout<<"enter second number\n ";
cin>>b;

cout<<"enter operator\n ";
cin>>op;
double result=0.0;

if(op == '+'){
cout<<a+b;

}else if(op == '-'){
cout<<a-b;

}else if(op == '/'){
cout<<a/b;

}else if(op =='*'){
cout<<a*b;

}while(op!='+','-','/','*'){

    cout<<"wrong operator\n ";
    cin>>op;
    
    return result;

}
}
coutop;
而(op!=“+”、“-”、“/”、“*”){
库托普;
}

欢迎使用Stack Overflow。您的答案可以通过添加特定的代码示例来改进。您希望继续询问多少次?
 cout<<"enter operator\n";
 cin>>op;
 while(op!='+','-','/','*'){
    cout<<"wrong operator\n ";
    cin>>op;
}