Make a simple calculator

The basic calculator are familiar with, there is a simple calculator addition, subtraction, multiplication, division four functions.
FIG follows
Here Insert Picture Description
here below I here logic, first determines the input operator symbols, then the digital input is determined to perform a calculation.

#include <iostream>
using namespace std;

int main()
{
	char operator;
	float num1, num2;

	cout << "输入运算符:+、-、*、/ : ";
	cin >> operator;

	cout << "输入两个数: ";
	cin >> num1 >> num2;

	switch (operator)// 此处判断输入的运算符
	{
	case '+':
		cout << num1 + num2;
		break;

	case '-':
		cout << num1 - num2;
		break;

	case '*':
		cout << num1 * num2;
		break;

	case '/':
		cout << num1 / num2;
		break;

	default:
		// 如果运算符不是 +, -, * 或 /, 提示错误信息
		cout << "请输入正确运算符。";
		break;

	}

	return 0;

}

Guess you like

Origin blog.csdn.net/qq_39686486/article/details/89962951