Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1e9;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}
int cards[10];
bool ok;
void saiki(int deep){
	if(deep==4){
		ok=true;
		return;
	}
	for(int i=1;i<=7;i++){
		if(cards[i]>0&&cards[i+1]>0&&cards[i+2]>0){
			cards[i]--;
			cards[i+1]--;
			cards[i+2]--;
			saiki(deep+1);
			cards[i]++;
			cards[i+1]++;
			cards[i+2]++;
		}
		for(int i=1;i<=9;i++){
			if(cards[i]>2){
				cards[i]-=3;
				saiki(deep+1);
				cards[i]+=3;
			}
		}
	}
	
}

int main(){
	
	int n;
	cin>>n;
	while(n>0){
		stack<string> a;
	string s;
		cin>>s;
		string tmp="";
		rep(i,s.size()){
			if(s[i]>='0'&&s[i]<='9'){
				tmp+=s[i];
			}
			else{
				if(!a.empty()&&s[i]!='('){
				string o=a.top();
					int k=0;
				if(o=="*"){
					a.pop();
					k=stoi(tmp)*stoi(a.top());
					a.pop();
					tmp=to_string(k);
					
				}
				else if(o=="/"){
					a.pop();
					k=stoi(a.top())/stoi(tmp);
					a.pop();
					tmp=to_string(k);
				
				}
					
					
				}
				if(tmp!=""){
				a.push(tmp);
				tmp="";
				}
					if(s[i]==')'){
						int k=stoi(a.top());
						a.pop();
							while(1){
									if(a.top()=="("){
										a.pop();
										if(!a.empty()){
											if(a.top()=="*"){
											a.pop();
												k=stoi(a.top())*k;
												a.pop();
											}
											else if(a.top()=="/"){
												a.pop();
												k=stoi(a.top())/k;
												a.pop();
											}
												
										}
										a.push(to_string(k));
										break;
									}
										else{
												if(a.top()=="+"){
									a.pop();
									k=k+stoi(a.top());
								}
								else if(a.top()=="-"){
									a.pop();
									k=stoi(a.top())-k;
								}
								a.pop();
										}
							}
								
						
					}
						else if(s[i]!='='){
							
							if(i==0&&s[i]=='-')
								tmp+=s[i];
							else if(s[i+1]=='-'){
								tmp+=s[i+1];
								string c="";
							c+=s[i++];
							a.push(c);
						}
							else{
								string c="";
							c+=s[i];
							a.push(c);
							}
							
						}
					
			}
				
		}
			int ans=stoi(a.top());
			a.pop();
			while(!a.empty()){
				if(a.top()=="+"){
				a.pop();
					ans=ans+stoi(a.top());
				}
				else if(a.top()=="-"){
				a.pop();
					ans=stoi(a.top())-ans;
				}
				a.pop();
				
			}
			cout<<ans<<endl;
			n--;
	}
	
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <int> VI;
typedef vector <char> VC;

string toNums( string s ) {
    string R = "+-*/";
    for ( int i = 0; i < 4; ++ i ) {
        replace( s.begin(), s.end(), R[i], ' ' );
    }
    return s;
}

string toOps( string s ) {
    string R = "0123456789";
    for ( int i = 0; i < 10; ++ i ) {
        replace( s.begin(), s.end(), R[i], ' ' );
    }
    return s;
}

int eval( string expr ) {
    stack <int> S;
    for ( int i = 0; i < (int)expr.size(); ++ i ) {
        if ( expr[i] == '(' ) {
            S.push( i );
        } else if ( expr[i] == ')' ) {
            int left = S.top();
            int right = i;
            string L = expr.substr( 0, left );
            string M = expr.substr( left, right - left + 1 );
            string R = expr.substr( right + 1 );
            ostringstream os;
            os << eval( M.substr( 1, M.size()-2 ) );
            expr = L + os.str() + R;
            i = -1;
            S = stack <int>();
            continue;
        }
    }
    string nums = toNums( expr );
    string ops = toOps( expr );
    VI N;
    int num;
    istringstream is1( nums );
    while ( is1 >> num ) {
        N.push_back( num );
    }
    VC O;
    char op;
    istringstream is2( ops );
    while ( is2 >> op ) {
        O.push_back( op );
    }
    for ( int i = 0; i + 1 < (int)N.size(); ++ i ) {
        int a = N[i], b = N[i+1];
        char c = O[i];
        if ( c == '*' ) {
            N.erase( N.begin() + i );
            N[i] = a * b;
            O[i] = O[i+1];
            i --;
        } else if ( c == '/' ) {
            N.erase( N.begin() + i );
            N[i] = a / b;
            O[i] = O[i+1];
            i --;
        }
    }
    int answer = N[0];
    for ( int i = 0; i + 1 < (int)N.size(); ++ i ) {
        if ( O[i] == '+' ) {
            answer += N[i+1];
        } else {
            answer -= N[i+1];
        }
    }
    return answer;
}

int main() {
    int n;
    while ( cin >> n ) {
        if ( n == 0 ) break;
        for ( int i = 0; i < n; ++ i ) {
            string line;
            cin >> line;
            cout << eval( line.substr( 0, line.size() - 1 ) ) << endl;
        }
    }
    return 0;
}