求大佬相助

B2052 简单计算器

sendaofangao @ 2023-05-19 10:21:27

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b;
    char c;
    cin>>a>>b>>c;
    if(C!='+'||C!='-'||C!='*'||C!='/')
    {
        cout<<"Invalid operator!";
    }
    else if(c=='/'&&b==0)
    {
        cout<<"Divided by zero!"
    }
    else
    {
        if(c=='+')
        {
            cout<<a+b;
        }
        else if(c=='-')
        {
            cout<<a-b;
        }
        else if(c=='/')
        {
            cout<<a/b;
        }
        else if(c=='*')
        {
            cout<<a*b;
        }
    }
    return 0;
}

本人萌新一枚 谢谢


by Pink_Cut_Tree @ 2023-05-19 10:34:47

if(C!='+'||C!='-'||C!='*'||C!='/')

变量 C 尚未定义,你前面定义的是 c

@sendaofangao


by hopeless_hope @ 2023-05-19 12:52:29

C改成c


by sendaofangao @ 2023-05-23 16:31:58

谢谢


|