@root 为什么只有90分???

12121 Game for peace 2024-05-26 14:36:47 37
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char c;
    cin >> a >> b >> c;
    if (c == '+'){
        cout << a + b;
    }
    else if (c == '-'){
        cout << a - b;
    }
    else if (c == '*'){
        cout << a * b;
    }
    else if (c == '/'){
        if (b != 0) cout << a / b;
    }
    else{
        cout << "Invalid operator!";
    }
    return 0;
}
{{ vote && vote.total.up }}

共 3 条回复

CHY-He

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

CHY-He

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

root 站长
    else if (c == '/'){
        if (b != 0) cout << a / b;
        //这里 b 等于 0 要输出语句 Divided by zero!
    }