zhw123123 @ 2023-06-11 15:00:42
结果显示编译错误,求大神找出错误
#include<bits/stdc++.h>
using naamespace std;
int main(){
int a,b;
char c;
cin>>a>>b;
cin>>c;
if(b==0&&c=='/'){
cout<<"Divided by zero!"<<endl;
return 0;
}
if(c=='+')
cout<<a+b<<endl;
else if(c=='-')
cout<<a-b<<endl;
else if(c=='*')
cout<<a*b<<endl;
else if(c=='/'){
if(b==0){
cout<<"Divided by zero!"<<endl;
return 0;
}
cout<<a/b<<endl;
}
else
cout<<"Invalid operator!"<<endl;
return 0;
}
by Small_rabbit @ 2023-06-11 15:08:55
naamespace 处要去一个‘a’!
by OldDriverTree @ 2023-06-11 15:09:30
@zhw123123 这不是通过了吗?
by zhw123123 @ 2023-06-11 15:11:24
感谢两位,问题竟这么小
by _lfggy__liangfeng__ @ 2023-06-11 15:47:10
其实你的判断除数为零和除法可以写在一起的……