四则混合运算c++简易
时间: 2024-05-25 21:07:25 浏览: 18
四则混合运算是指在C++中进行加减乘除等基本运算的组合。下面是一个简易的四则混合运算的C++代码示例:
```cpp
#include <iostream>
int main() {
int num1, num2;
char op;
std::cout << "请输入第一个操作数:";
std::cin >> num1;
std::cout << "请输入运算符(+、-、*、/):";
std::cin >> op;
std::cout << "请输入第二个操作数:";
std::cin >> num2;
switch (op) {
case '+':
std::cout << "结果:" << num1 + num2 << std::endl;
break;
case '-':
std::cout << "结果:" << num1 - num2 << std::endl;
break;
case '*':
std::cout << "结果:" << num1 * num2 << std::endl;
break;
case '/':
if (num2 != 0) {
std::cout << "结果:" << num1 / num2 << std::endl;
} else {
std::cout << "除数不能为0!" << std::endl;
}
break;
default:
std::cout << "无效的运算符!" << std::endl;
break;
}
return 0;
}
```
相关推荐
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)