简单计算器

#include 
#include 
#include 
using namespace std;
const int maxn = 10005;
int main(){
    int sum = 0,a = 0,b = 0;
    char c;
    cin >> a;
    while(true){
        scanf("%c",&c);
        if(c == '=')
            break;
        scanf("%d",&b);
        if(c == '+')
            a += b;
        else if(c == '-')
            a -= b;
        else if(c == '*')
            a *= b;
        else if(c == '/'){
            if(b != 0)
                a /= b;
            else{
                cout << "ERROR";
                return 0;
            }
        } else{
            cout << "ERROR";
            return 0;
        }
    }
    cout << a;
    return 0;
}

你可能感兴趣的:(简单计算器)