【发布时间】:2015-04-12 11:31:30
【问题描述】:
我想开发一个独特的计算器。所以,我在玩它,但现在我真的对这个功能感到困惑:
//Calculate two input expressions.
@prvni - First expression.
@druhe - Second expression.
@operace - Specifies mathematical operations - addition, multiplication etc.
int vypocti(int prvni, int druhe, char operace){
return (prvni+operace+druhe);
}
所以,我正在尝试使用“operace”参数作为数学函数。 (如下例所示。)
if(dpik == '+'){
cout<<vypocti(prvni, druhe, '+');
}
你能帮帮我吗?
【问题讨论】:
-
你不能这样,c++ 不是脚本语言。你必须映射它来调用正确的数学运算:
if(operace == '+') { return prvni + druhe; }
标签: c++ operators calculator