C++计算器代码

#include <iostream>
using namespace std;

int main()
{
	while(true)
	{
		try
		{
			int x;
			scanf("%d",&x);
			char c;
			scanf("%c",&c);
			int y;
			scanf("%d",&y);
			
			switch(c)
			{
			case ‘+‘:
				cout<<x+y<<endl;
				break;
			case ‘-‘:
				cout<<x-y<<endl;
				break;
			case ‘*‘:
				cout<<x*y<<endl;
				break;
			case ‘/‘:
				if(y==0) cout<<"除数不可以为0"<<endl;
				else
				cout<<x/y<<endl;
				break;
			default:
				break;
			}	
		}
		catch(exception e)
		{
			cout<<"出错!"<<endl;
		}
		
	}
	

	return 0;
}
通过编译

C++计算器代码,布布扣,bubuko.com

C++计算器代码

上一篇:mysql 搭建主从


下一篇:springboot_项目结构_数据库