2019Visual Studio做四则计算器代码
时间: 2023-05-18 12:04:45 浏览: 116
以下是一个简单的四则运算计算器的代码,使用 Visual Studio 2019 编写:
#include <iostream>
using namespace std;
int main()
{
char op;
double num1, num2;
cout << "请输入运算符 (+, -, *, /): ";
cin >> op;
cout << "请输入两个数字: ";
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 '/':
cout << num1 << " / " << num2 << " = " << num1/num2;
break;
default:
// 如果运算符不是 +, -, *, 或 /,输出错误信息
cout << "错误的运算符";
break;
}
return 0;
}
阅读全文