杭电oj1170

根据输入的数学字符±*/计算数值
需要注意:The result should be rounded to 2 decimal places If and only if it is not an integer.!!!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int T;
    int A,B;
    char C;
	cin>>T;
	while(T--){
		cin>>C>>A>>B;
			switch(C){
			case '+':
			cout<<A+B<<endl;
			break;
			case '-':
			cout<<A-B<<endl;
			break;
			case '*':
			cout<<A*B<<endl;
			break;
			}
		    if(C=='/'){
		    	if(A%B!=0)
			//printf("%.2lf\n",A/B); 
			//刚开始就是这样错的,输出了0.00 
				printf("%.2lf\n",A/(double)B); 
			else
			    cout<<A/B<<endl;
		    } 
		
		
		
		
	} 
	return 0;
}
发布了13 篇原创文章 · 获赞 0 · 访问量 204

猜你喜欢

转载自blog.csdn.net/weixin_45191675/article/details/104695484