devc++简易计算器代码
时间: 2024-06-09 13:03:12 浏览: 182
VC++简易计算器代码
Dev-C++是一个免费的、开源的集成开发环境,支持C/C++编程语言。下面是一个简单的计算器代码示例:
```c++
#include <iostream>
using namespace std;
int main()
{
char op;
double num1, num2;
cout << "请输入操作符(+、-、*、/):";
cin >> op;
cout << "请输入两个数字:" << endl;
cin >> num1 >> num2;
switch(op)
{
case '+':
cout << num1 << "+" << num2 << "=" << num1+num2;
break;
case '-':
cout << num1 << "-" << num2 << "=" << num1-num2;
break;
case '*':
cout << num1 << "*" << num2 << "=" << num1*num2;
break;
case '/':
if(num2 != 0)
cout << num1 << "/" << num2 << "=" << num1/num2;
else
cout << "除数不能为0!";
break;
default:
cout << "无效的操作符!";
break;
}
return 0;
}
```
阅读全文