题解 | #实现简单计算器功能#
实现简单计算器功能
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; }