求助!

B2052 简单计算器

zzq2010 @ 2023-11-19 14:32:56

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c;//数字
    string d;//字符
    cin>>a;
    cin>>b;
    cin>>d;
    if(b==0){
        cout<<"Divided by zero!";
    }
    if (d == "+"){
        c=a+b;
        cout<<c;
    }else if (d == "/"){
        c=floor(a/b);
        cout<<c;
    }else if (d == "*"){
        c=a*b;
        cout<<c;
    }else if (d == "-"){
        c=a-b;
        cout<<c;
    }else if (d!="-"||d!="/"||d!="*"||d!="+"){
        cout<<"Invalid operator!";
    }
};

by lzm0107 @ 2023-11-19 14:35:14

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c;//数字
    string d;//字符
    cin>>a;
    cin>>b;
    cin>>d;
    if(b==0 && d == "/"){
        cout<<"Divided by zero!";
        return 0;
    }
    if (d == "+"){
        c=a+b;
        cout<<c;
    }else if (d == "/"){
        c=a/b;
        cout<<c;
    }else if (d == "*"){
        c=a*b;
        cout<<c;
    }else if (d == "-"){
        c=a-b;
        cout<<c;
    }else if (d!="-"||d!="/"||d!="*"||d!="+"){
        cout<<"Invalid operator!";
    }
};

by chenyyegg @ 2023-11-19 15:04:45

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c;//数字
    char d;//字符
    cin>>a>>b>>d;
    if(b==0 && d == "/"){
        cout<<"Divided by zero!";
        return 0;
    }
    else if (d == "+"){
        c=a+b;
        cout<<c;
    }else if (d == "/"){
        c=a/b;
        cout<<c;
    }else if (d == "*"){
        c=a*b;
        cout<<c;
    }else if (d == "-"){
        c=a-b;
        cout<<c;
    }else if (d!="-"&&d!="/"&&d!="*"&&d!="+"){
        cout<<"Invalid operator!";
    }
  return 0;
}

by zzq2010 @ 2023-11-21 21:38:28

@chenyyegg 谢谢,过了


by zzq2010 @ 2023-11-21 21:38:48

@lzm0107 谢谢


|