题解 | #简单计算器#
简单计算器
http://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239
int main()
{
double a,b,z;
char c;
while(scanf("%lf%c%lf",&a,&c,&b)!=EOF)
{
if(c!='+' && c!='-' && c!='*' && c!='/')
{
printf("Invalid operation!");
continue;
}
else if(c=='+')
{
z=a+b;
}
else if(c=='-')
{
z=a-b;
}
else if(c=='*')
{
z=a*b;
}
else if(c=='/')
{
if(b==0)
{
printf("Wrong!Division by zero!");
continue;
}
else
{
z=a/b;
}
}
printf("%.4lf%c%.4lf=%.4lf",a,c,b,z);
}
return 0;
}