T1048 简单计算器

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    char c;
    cin>>a>>b>>c;
    if(b==0)
    {
        cout<<"Divided by zero!"<<endl;
    }
    else if(c!='+'&&c!='-'&&c!='*'&&c!='/')
    {
        cout<<"Invalid operator!"<<endl;
    }
    else if(c=='+')
    {
        cout<<a+b<<endl;
    }
    else if(c=='-')
    {
        cout<<a-b<<endl;
    }
    else if(c=='/')
    {
        cout<<a/b<<endl;
    }
    else if(c=='*')
    {
        cout<<a*b<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_29488513/article/details/89053379