题解 | #实现简单计算器功能#

实现简单计算器功能

https://www.nowcoder.com/practice/e7c08272a4b7497fb990ce7abb1ee952

#include <iostream>
using namespace std;

int main() {

    //char str[100] = { 0 };
    //cin.getline(str, sizeof(str));

    // write your code here......
    string op;
    int x;
    int y;
    cin >> op >> x >> y;

    if (op == "add")
    {
        cout << x + y;
    }
    else if (op == "sub")
    {
        cout << x - y;
    }
    else if (op == "mul")
    {
        cout << x * y;
    }
    else if (op == "div")
    {
        if (y == 0)
        {
            cout << "Error";
        }
        else 
        {
            cout << x / y;
        }
    }

    return 0;
}

全部评论

相关推荐

09-22 19:21
南京大学 Java
牛客96763241...:刚刚想说才投十几个,养生呢,结果一看是南大本硕✌️,肯定没有问题的
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
09-19 12:15
门头沟学院 Java
迷茫的大四🐶:这下是真的打牌了,我可以用感谢信和佬一起打牌吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务