0分求助
查看原帖
0分求助
1086459
Ghy_boy楼主2023/11/1 18:43
#include<bits/stdc++.h>
using namespace std;
int d(int a,int b,char c,bool z){
	bool xe=0;
	if(c=='+'){return a+b;}
	if(c=='-'){return a-b;}
	if(c=='*'){return a*b;}
	if(c='/'){
		if(b==0) {z=1;return z;}
		if(b>0) return a/b;
	}
	
}
int main(){
	int a,b;
	char c;
	bool z=0;
	cin>>a>>b>>c;
	if(c != '+' && c != '-' && c != '*' && c != '/'){
		cout<<"Invalid operator!";
		return 0;
	}
	if(d(a,b,c,z)==1){
		cout<<"Divided by zero!";
		return 0;
	}
	else{
		cout<<d(a,b,c,z);
	}


	return 0;
}

2023/11/1 18:43
加载中...