C ++基本计算器 -

时间:2015-04-12 11:31:31

标签: c++ operators calculator

我想开发一个独特的计算器。所以,我玩它但现在我对这个功能感到困惑:

//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, '+');
}
你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

πάνταῥεῖ的评论非常有帮助:

  

你不能这样,c ++不是一种脚本语言。你必须将它映射为调用正确的数学运算:if(operace == '+') { return prvni + druhe; }