题目描述
Simple Calculator Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is ‘+’, ‘-‘, ‘*’ or ‘/’ (sum, difference, product or quotient). The division should truncate any fractional part.
输入
The input consists of multiple datasets. Each dataset is given in the following format. a op b The input ends with a single ‘?’. Your program should not process for this terminal symbol.
输出
For each dataset, print the value in a line.
重点就在于比较符号是否相等
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,z,s;
while(scanf(“%d %c %d”,&a,&z,&b)!=EOF){
if (z==’+’){
s=a+b;
}
if (z==’-‘){
s=a-b;
}
if (z==’*‘){
s=a*b;
}
if (z==’/‘){
s=a/b;
}
if (z==’?’){
return 0;
}
cout<<s<<endl;
s=0;
}
}