这个是怎么回事,为什么会这样输出,求各位大神帮助!
#include <iostream>using namespace std;
int main() {
int a,b;
char n;
cin >> a >> b >> n;
if(n = '/' && b == 0) {
cout << "Divided by zero!" << endl;
return 0;
}
if(n == '+') {
cout << a+b << endl;
}else if(n == '-') {
cout << a-b << endl;
}else if(n == '*') {
cout << a*b << endl;
}else if(n == '/') {
cout << a/b << endl;
}else{
cout << "Invalid operator!" << endl;
}
return 0;
}
运行输入样例:1 2 +
本应输出:3
实际输出:Invalid operator!
求大神帮忙看看哪里的问题