@root 为什么是Runtime Error?

12121 Game for peace 2024-05-25 15:37:53 2024-05-26 14:33:55 19
#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 == '/'){
        cout << a / b;
    }
    else{
        cout << "Invalid operator!";
    }
    return 0;
}
{{ vote && vote.total.up }}

共 2 条回复

12121 Game for peace

谢谢!

root 站长

乘法的除数不能为 0,所以这个地方要先判断除数是否为 0