luyanmin @ 2022-05-21 16:21:36
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b;
char fu;
cin>>a>>b>>fu;
switch(fu){
case'+': cout<<a+b;break;
case'-': cout<<a-b;break;
case'*': cout<<a*b;break;
case'/':
if(b!=0) {
cout<<a/b;
}
else {
cout<<"Divided by zero!";break;
}
default: cout<<"Invalid operator!";
}
return 0;
}
by Argon_Cube @ 2022-05-21 16:27:47
@luyanmin 2 3 /
by Lhy2021 @ 2022-05-21 16:31:08
是全错吗
by Const_int_MAXN @ 2022-05-21 16:31:23
@Epsilon_Cube
除号表示整除,结果向 0 取整。
by jimmyfj @ 2022-05-21 16:31:47
@luyanmin 调好了
by jimmyfj @ 2022-05-21 16:34:18
@luyanmin 你那个 cout<<a/b; 后面漏了 break; 不然还会输出Invalid operator!
by Argon_Cube @ 2022-05-21 16:34:34
@Const_int_MAXN 他if
里没加break
。
by luyanmin @ 2022-05-21 16:37:43
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b;
char fu;
cin>>a>>b>>fu;
switch(fu){
case'+': cout<<a+b;break;
case'-': cout<<a-b;break;
case'*': cout<<a*b;break;
case'/':
if(b!=0) {
cout<<a/b;break;
}
else {
cout<<"Divided by zero!";
}break;
default: cout<<"Invalid operator!";
}
return 0;
}
by jimmyfj @ 2022-05-21 16:38:41
@luyanmin
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a, b;
char c;
cin >> a >> b >> c;
switch(c)
{
case'+': cout << a + b;break;
case'-': cout << a - b;break;
case'*': cout << a * b;break;
case'/':
if(b != 0)
{
cout << a / b;
break;
}
else {cout<<"Divided by zero!";break;}
default: cout<<"Invalid operator!";
}
return 0;
}
by luyanmin @ 2022-05-21 16:39:03
过了,谢谢大家
by Const_int_MAXN @ 2022-05-21 16:43:23
@Epsilon_Cube 知道了谢谢